Information Technology Reference
In-Depth Information
Fig. 2.4
Overriding
vehicle that you have used since. This is the only car that you are familiar with; the
only car that you know how to operate. Now, imagine that one day, your compact
sedan breaks down. In order to go to work, you are required to borrow a friend's
car. This car, though, is not a compact sedan. It is a luxury SUV. How, then, will
you be able to drive this vehicle without prior knowledge of its specific operation?
In reality, we know that the problem posed above probably will not be a
problem at all. It seems reasonable enough, though, to assume that a compact
sedan and a luxury SUV have different enough inner workings to require separate
and distinct methods of operation. Why, then, would the knowledge of how to
operate one allow us the ability to operate the other? The answer is that both the
compact sedan and the luxury SUV share a common interface through which they
can be accessed. Simply put, most, if not all, of the control methods for one also
work for the other. This common method of access is of course based on some
general idea of how an automobile should be used. Put another way, both
compact_sedand and luxury_SUV have inherited a common interface from
the superclass automobile , which allows them to perform a set of general
functions based on the same methods of access.
Polymorphism is an engineering concept concerning the ability of separate
classes and their derived instances to be accessed in the same way, assuming they
are derived from the same superclass (Booch 1994 ). This method of access is
provided for in a common interface that is defined in the superclass. This provides
a level of encapsulation by hiding the inner workings of a class or object from the
user, while allowing access in a familiar way. In the example above, the compact
sedan and the luxury SUV are both started in the same manner, with the insertion
of a key into the ignition, and the turning of that key. The internal actions that fire
up the two vehicles, however, may be entirely different from one and other. So, to
narrow our definition, polymorphism dictates that a common interface can be used
to access the unique inner workings of separate classes that are related by a
common superclass. Polymorphism is a powerful tool that permits the use of
 
Search WWH ::




Custom Search