Java Reference
In-Depth Information
Physician
Automobile
Pediatrician
Chassis
Engine
Surgeon
Gen/Spec Structure
(is-a-kind-of relation)
Whole/Part Structure
(is-a-part-of relation)
Figure 14-4 Class Inheritance Notation
Polymorphism and Abstract Classes
In object-orientation it is possible to have a class that defines an interface
to the system but contains no specific implementation. In other words, it is
possible to create a class with dummy methods, that provide no actual pro-
cessing. All these dummy methods do is define the interface to the class sys-
tem. When a class contains no actual implementation we say that it is an
abstract class . Methods that define the interface but contain no implemen-
tation are called abstract methods .
In Java programming an abstract class is one that has at least one ab-
stract method. The purpose of abstract classes and abstract methods is to
achieve greater generalization. The abstract class defines the protocol
that must be followed to access the subclasses located lower in the hier-
archy. The implementation is left to the lower-level classes. In this man-
ner a dummy method (abstract method) is used as a template for the
interface of a concrete method that shares the same name.
The idea of having several methods with the same name is called poly-
morphism . Literally, polymorphism means to have many forms. In ob-
ject-oriented programming the term polymorphism is used in reference to
a class or class system that contains two or more methods that share the
same name. Polymorphism is used to implement class abstraction by hav-
ing several methods with the same name (called polymorphic methods)
located in different classes. Usually the method located in the highest
class in the hierarchy is an abstract method. The abstract method defines
the interface for all its polymorphic relatives, but provides no implemen-
 
Search WWH ::




Custom Search