Dynamic Method Dispatch
TLDR: Dynamic method dispatch, also known as runtime polymorphism, is a mechanism in object-oriented programming that determines which method implementation to execute based on the runtime type of an object. This feature enables flexible and extensible designs, as the method called is resolved at runtime rather than compile-time. Dynamic method dispatch is widely used in languages like Java and CPP to support polymorphism and inheritance hierarchies.
https://en.wikipedia.org/wiki/Polymorphism_(computer_science)
In Java, dynamic method dispatch is achieved when a method in a superclass is overridden by a subclass, and the method call is made using a reference to the superclass but pointing to an object of the subclass. For example, if `Animal` is a superclass with a method `move()`, and `Bird` is a subclass overriding `move()`, calling `move()` on an `Animal` reference to a `Bird` object will invoke the `Bird` implementation. This ensures that the appropriate behavior is executed, even if the reference type is generic.
https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html
The power of dynamic method dispatch lies in its support for extensibility. It enables the addition of new behaviors by creating subclasses without altering the existing codebase, adhering to the open-closed principle in software design. This mechanism underpins frameworks and libraries where generic interfaces interact with various concrete implementations. While dynamic resolution introduces slight performance overhead, its benefits in enabling modular and reusable code make it indispensable in object-oriented programming.
https://docs.oracle.com/javase/specs/jls/se20/html/jls-15.html