Object Oriented Analysis and Design
module 06
Dr Abu-Eesa
Islamic Online University
Polymorphism & dynamic binding
Poly : many
Morph: change or form
Polymorphism: ability in programming to present the same interface for
differing underlying forms (data types)
Shape (Circle and square)
Polymorphism: [Link]()
Classical way: drawSquare() and drawCircle()
Polymorphism & dynamic binding
1. Any object of type SubClass1 or SubClass2 can be stored in a
reference of type SuperClass.
2. No object of type SubClass1 (SubClass2) can be stored in a
reference of type SubClass2 (SubClass1).
3. A reference of type SuperClass can be cast as a reference of
type SubClass1 or SubClass2.
Student class
The grade point average(GPA)
UndergraduateStudent class
isInGoodStanding class
Inheritance in python
Source: [Link]
isinstance() and issubclass()
Protected Fields and Methods
More suitable definition of Protected access
The code present in a class A may access a protected attribute of an object
of class B ONLY IF B is at least of type A
i.e., B belongs to the hierarchy rooted at A.
Encapsulation
Encapsulation is an Object Oriented Programming concept that binds
together the data and functions that manipulate the data, and that keeps
both safe from outside interference and misuse.
(source: tutorialspoint)
Python: Private, protected and public
Public
Source: [Link]
Protected
Private
The object class
Genericity
Mechanism for creating entities that vary in their parameter types
Placeholders called generic parameters
Stack example:
Stack example continued…..
Data field of stackNode: stores elements of the stack
Create a stack & store integer object (some drawbacks)
Following code generates an error
Generics provides solution; A generic stack class example:
Stack with only integer objects:
Following statement will trigger error message from compiler: