Part 1 of 7 · 1 min read
Why this page comes fifth
In this module you will
- Define polymorphism and dynamic binding in plain words.
- Write a subtype that overrides a method and call it through the parent type.
- Replace a type tag and a
switchwith a class hierarchy. - Spot when a chain of
iforinstanceoftests signals missing polymorphism. - Say what makes a replacement safe (an early look at the Liskov idea of Level 2).
Modules 3 and 4 gave interfaces and reuse. Polymorphism is what makes those interfaces useful at run time, and it is the main tool for removing if chains. The sources are "Design Patterns" (GoF), chapter 1, and "Effective Java" (EJ) Item 23. Code was compiled and run before it was written here. Numbers marked "made up" only show the idea.