0% found this document useful (0 votes)
45 views3 pages

OOP: Inheritance & Polymorphism Overview

The document discusses the object-oriented programming concepts of inheritance and polymorphism. It defines polymorphism as the ability for one reference type to take on multiple meanings or forms. This allows for easily extensible applications where a base class reference can be used to assign objects of derived classes. An example given is sending a generic "move" command to different types of animals in a game via a base animal class reference. The document also provides an example of how a hospital manager could interact with doctors in the same way regardless of their specialty, through polymorphism.

Uploaded by

Super Rome
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views3 pages

OOP: Inheritance & Polymorphism Overview

The document discusses the object-oriented programming concepts of inheritance and polymorphism. It defines polymorphism as the ability for one reference type to take on multiple meanings or forms. This allows for easily extensible applications where a base class reference can be used to assign objects of derived classes. An example given is sending a generic "move" command to different types of animals in a game via a base animal class reference. The document also provides an example of how a hospital manager could interact with doctors in the same way regardless of their specialty, through polymorphism.

Uploaded by

Super Rome
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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