You are on page 1of 3

OBJECT ORIENTED PROGRAMMING

WEEK 13: Inheritance and Polymorphism

OOP CONCEPT: POLYMORPHISM

Learning Outcomes:

Design a program that apply an Inheritance and polymorphism in programming to test and debug
the program

REVIEW:

Figure 1: UML CLASS DIAGRAM


OBJECT ORIENTED PROGRAMMING
WEEK 13: Inheritance and Polymorphism

Polymorphism

• Polymorphism is the key concept in object oriented programming


• Polymorphism literally means many forms
• Essentially we are able to get many different types of object behaviour from a single
reference type
• This enables us to write easily extensible applications
• Polymorphism is implemented through references to objects
• We can assign base class object references to any derived class object
• to assign multiple meanings to the same method name

Example 1:

• In a computer game that simulates the movement of animals we can send ‘move’
commands to different types of animal
• We send the commands via an animal reference which is the base class for the different
animal types
• But each type behaves differently once it receives the command
• Such an approach leads to a readily extendable application
OBJECT ORIENTED PROGRAMMING
WEEK 13: Inheritance and Polymorphism

EXAMPLE 2:
Make one statement about how a hospital manager may interact with all doctors employed at
their hospital irrespective of what type of doctor they are.

FEEDBACK 2:
You may have considered that a hospital manager could pay all the doctors (presumably this
will be done automatically at the end of every month) and could discipline any doctor guilty of
misconduct – of course this would be true for other staff as well. More specifically a manager
could check that a doctor’s medical registration is still current. This would be something that
management would need to do for all doctors irrespective of what their specialism is.

Using the same idea of polymorphism allows computer systems to be extended, with new
specialized objects being created, while allowing current parts of the system to interact with
new object without concern for the specific properties of the new object.

You might also like