Polymorphism
Adding a new type using polymorphism requires only creating a new subclass, with no changes to existing code. With polymorphism, the calling code does not need to know which specific type it is working with. Polymorphism replaces switch st…
1 sources - 5 claims
Adding a new type using polymorphism requires only creating a new subclass, with no changes to existing code. With polymorphism, the calling code does not need to know which specific type it is working with. Polymorphism replaces switch statements by encapsulating each case in its own class or method. In a polymorphic design, the correct behavior is determined by the object's type at runtime. A base class with shared interface methods and type-specific subclasses is the polymorphic model for handling varied behavior.