|
||
| Lesson 2
Objective
|
Designing Reusable Polymorphism
Define polymorphism and explain why it is central to OOP. |
|
|
Polymorphism is a way of giving different meanings to the same message. The meanings are dependent on the type of data being
processed. Object orientation takes advantage of polymorphism by linking behavior to the object's type. In addition, polymorphism
localizes responsibility for behavior. The client code frequently requires no revision when additional functionality is added to the
system through implementor-provided code additions.
In effect, polymorphism is the genie in OOP, taking instruction from a client and properly interpreting its wishes.
Polymorphism in the context of object-oriented programming is the ability of one type alpha
to appear as and be used like another type beta.
The purpose of polymorphism is to implement a style of programming called message-passing in which objects of various types
define a common interface of operations for users.
In strongly typed languages, polymorphism usually means that type alpha somehow derives from type beta, or type gamma implements an interface that represents type beta. In weakly typed languages types are implicitly polymorphic. |
||
|
|
||