




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lecture script on polymorphism and dynamic binding in object-oriented programming (oop) by dr. Jamil ahmed. It explains the concept of message-sending between objects, the ability of different objects to respond differently to the same message (polymorphism), and the benefits of combining polymorphism with dynamic binding. The document also covers method overriding, substitution, and the disadvantages of polymorphism and dynamic binding.
Typology: Slides
1 / 8
This page cannot be seen from the preview
Don't miss anything!





1
Lecture 8
2
n A computer program involving objects is a sequence of message-sends n When an object receives a message that it understands, it invokes some behavior (encapsulated)
n Various kinds of objects can understand the same message, but respond differently
3
4
n The ability for different kinds of objects to respond differently to the same message is called Polymorphism
5
6
n aLecturer.canDo(someDuty)
n aHoD.canDo(anotherDuty)
n Is that all? Yes, Monomorphic methods
Inherited behavior; Code reused
No, there is more than that
10
n With an interpreted language like BASIC each line of code is dealt with as it comes to the interpreter and only then it is converted into machine-readable code n This is termed dynamic binding (or late binding ) n OO languages’ dynamic binding makes polymorphism really powerful by allowing to connect the appropriate method to the object at run-time
11
that is, polymorphism and dynamic binding…together…
12
n Remember, we said earlier that whenever we talk about objects belonging to a class we include objects belonging to subclasses
n What does this imply?
Lecturer HoD
13
n Suppose the code of class A uses an object belonging to class B. The class A should continue to work expectedly (correctly) if the object of class B is substituted by any other object belonging to any subclass of class B.
14
n Suppose lecturer is a collection of Lecturer objects
n The collection includes Lecturers and HoDs n Consider the implementation: for(int i = 0; i<lecturer.length;i++) lecturer[i].canDo(seminarOrganization)
n Message-send is dynamically bound to the appropriate code
15
n In C++, only virtual methods have this behavior
19
20
n Message sending
n Object Composition: Objects can be defined in terms of other objects
n Behavioral Refinement or Generalization: Classes can be described in terms of other classes
21
n Something is object-oriented if it can be extended by composition of existing parts or by refinement of behaviors.
Changes in the original parts propagate, so that compositions and refinements that reuse these parts change appropriately
22
n “Object Oriented” begins…