|Bruce Eckel’s Thinking in Java||Contents | Prev | Next|
is the third essential feature of an object-oriented programming language,
after data abstraction and inheritance.
provides another dimension of separation of interface from implementation, to
Polymorphism allows improved code organization and readability as well as the
programs that can be “grown” not only during the original creation
of the project but also when new features are desired.
creates new data types by combining characteristics and behaviors.
Implementation hiding separates the interface from the implementation by making
This sort of mechanical organization makes ready sense to someone with a
procedural programming background. But polymorphism deals with decoupling
in terms of
In the last chapter, you saw how inheritance
allows the treatment of an object as its own type
its base type. This ability is critical because it allows many types (derived
from the same base type) to be treated as if they were one type, and a single
piece of code to work on all those different types equally. The polymorphic
method call allows one type to express its distinction from another, similar
type, as long as they’re both derived from the same base type. This
distinction is expressed through differences in behavior of the methods you can
call through the base class.
this chapter, you’ll learn about polymorphism (also called dynamic
from the basics, with simple examples that strip away everything but the
polymorphic behavior of the program.