A well-defined class hierarchy can substantially
increase code reuse (decrease the code required), and improve reliability through reduced redundancy or duplication.
Related to inheritance is the concept of polymorphism. Polymorphism means, ???taking many forms.???
In OO programming, polymorphism means that the execution of a method of a given name may be different
depending on the class of the object for which the method is invoked.
For instance, suppose that instances of both the automobile class and the limousine class must be parked
from time to time. However, parking a limousine may require a different behavior; in particular, a limousine
will require a much bigger parking space. Therefore, the park() method of the limousine class will seek a
space of a different size than the park() method of the automobile class.
Suppose that the object vehicle can sometimes be an automobile, and sometimes be a limousine.
When vehicle must be parked, the program will invoke the park() method on the particular car or
limousine (e.g., vehicle.park()). The programmer doesn??™t have to worry about whether vehicle is an
automobile or a limousine. If the instance is an automobile, the automobile method will be invoked; if the instance is
a limousine, the limousine method will be invoked.
Pages:
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151