volume_mute

Polymorphism as a Refactoring Solution

publish date2026/06/24 21:27:37.851072 UTC

volume_mute

In object-oriented languages, what technique can often replace scattered switch (case) statements that depend on an object's type?

Correct Answer

Polymorphism, where different subclasses provide their own implementation of a common operation

Explanation

In object-oriented languages, polymorphism can often replace switch (case) statements that depend on the type of a value. Instead of one large switch statement scattered across the program, each subclass implements its own version of the behavior, reducing duplication and improving maintainability.

Reference

Software Engineering, Ian Sommerville, 10th edition


Quizzes you can take where this question appears