Object Oriented Analysis and Design
module 05
Dr Abu-Eesa
Islamic Online University
Inheritance
Classes may share many similarities but also significant differences
Suppose class C1 and C2
Class B = extract common aspects of C1 and C2
Class B will implement all the functionality
C1 and C2 can be much smaller containing only properties and methods
unique to them
Ancestor and descendants
Hierarchy example
Company sells many products, for example:
TVs
Books
CD’s
DVD’s
pens
Class product
java
python
Inheriting from product
Structure of class
Simplistic view of application
Create object
Inheriting from an interface
Interfaces – chapter 2 in text
1. The class StudentLinkedList implements the interface StudentList.
So variables of type StudentLinkedList are also of type StudentList.
2. We declared students as of type StudentList and not StudentLinked
List.
3. We restricted ourselves to using the methods of the interface
StudentList.
Why doesn’t python have interfaces?
Inheriting from an interface
Back to inheritance
realisation
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()