Replace switch-case with Polymorphism in Object-Oriented Programming
Description
Switch-case statements can be replaced with polymorphism to improve scalability and maintainability.
Original Code (Outdated)
switch(type) {
case "circle": drawCircle(); break;
case "square": drawSquare(); break;
}
Updated Code (Modern)
interface Shape { void draw(); }
class Circle implements Shape { public void draw() { /*...*/ } }
class Square implements Shape { public void draw() { /*...*/ } }
Shape shape = getShape(type);
shape.draw();