0% found this document useful (0 votes)
8 views21 pages

Module 06

The document discusses key concepts of Object Oriented Analysis and Design, focusing on polymorphism, dynamic binding, and encapsulation. It explains how polymorphism allows different data types to be treated through a common interface and highlights the importance of inheritance, access modifiers (public, protected, private), and generics in Python. Additionally, it provides examples related to class structures and the use of generics in creating flexible data structures like stacks.

Uploaded by

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

Module 06

The document discusses key concepts of Object Oriented Analysis and Design, focusing on polymorphism, dynamic binding, and encapsulation. It explains how polymorphism allows different data types to be treated through a common interface and highlights the importance of inheritance, access modifiers (public, protected, private), and generics in Python. Additionally, it provides examples related to class structures and the use of generics in creating flexible data structures like stacks.

Uploaded by

kalamkumar22
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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:

You might also like