





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
This lecture was delivered by Agstya Rao at Bidhan Chandra Krishi Viswa Vidyalaya for Object Oriented Programming course. It inlcudes: Relationship, Objects, Inheritance, Association, Polymorphism, Dynamic, Binding, Dependency, Aggregation, Composition
Typology: Slides
1 / 9
This page cannot be seen from the preview
Don't miss anything!






1
Lecture 6
2
n What are different kinds of relationships between classes/ objects? n Inheritance n Association n Dependency n Aggregation n Composition n Polymorphism n Dynamic Binding
3
n Objects
n Messages and methods
n Classes
n Inheritance
n Polymorphism
n Dynamic Binding
4
n When programming a class the data and responsibilities will become: n class variables i.e. values stored in the class as a whole n instance variables i.e. values stored in each instance n class methods i.e. methods the CLASS can do n instance methods i.e. methods an INSTANCE of the CLASS can do (after
5
n A Customer Class may have: n class variables - totalNumberOfCustomers n instance variables - customerAddress n class methods - new (how to create a new Customer) n instance methods - updateAddress
6
10
n inheritance is_type_of - inherits properties from another class n association uses_a - sends a message to another object/class
11
n dependency depends_upon – rely upon other objects
n aggregation consists_of - built up of other objects/classes
n composition consists_of - strongly owns other objects/ classes
12
13
n Inheritance is a key concept of OO paradigm n Like a set of similar objects is described by a class, Inheritance can be used to relationships of similarity
n Example: MonthlyPaidEmployee and HourlyPaidEmployee
14
n The approach enables generalisation to occur – means of managing complexity n Code reuse without duplication n A language-provided mechanism for sharing the data/ methods amongst the classes and objects n Allows extension of the hierarchy n By enables creation of new classes from existing classes by only considering the differences
15
e m p lo y e e N u m b e r : i n t^ E m p lo y e e d a t e O f B i r t h : D a t e n a m e : S t r i n g o r g a n i z a t i o n : S t r i n g d e p a r t m e n t C o d e : in t p o s i t i o n C o d e : i n t d a t e O f A p p o in t m e n t : D a t e
M o n t h lyP a id E m p loy e e m o n t h l y S a la ry : flo a t
W e e k lyP a id E m p lo y e e w e e k lyW a g e : flo a t
H o u rlyP a id E m p lo y e e h o u r l y R a t e : f l o a t h o u r s W o r k e d : f l o a t
E m p lo y e e e m p lo y e e N u m b e r : in t d a t e O f B i r t h : D a t e n a m e : String o r g a n i z a t io n : String d e p a r t m e n t C o d e : in t p o s i t i o n C o d e : i n t d a t e O f A p p o i n t m e n t : D a t e
19
n The key phrase for finding inheritance is X is a kind of Y n Inheritance can be: n single - each class has only one superclass to inherit from n multiple - each class can take properties
20
n Car inherits some properties from LandVehicle : n ( Data ) four wheels, red n ( Behaviour ) starts, stops n Car inherits some properties from HouseHoldItems: n ( Data ) owner, address n ( Behaviour ) getsNewOwner LandVehicle HouseHold Items
Car
21
n Multiple inheritance gives advantages especially in terms of re-usability, but has practical problems n What if both LandVehicle and HouseholdItems have different methods both called moveLocation - which would Car inherit?
22
e m p lo y e e N u m b e r : in t^ E m p lo y e e d a t e O f B ir th n a m e : S t r in g : D a t e o r g a n iz a t io n d e p a r t m e n t C o d e : S t r i n g : in t p o s i t i o n C o d e : int d a t e O f A p p o in t m e n t : D a t e
M o n t h lyP a id E m p lo y e e m o n t h l y S a la r y : f lo a t W e e k lyP a id E m p lo y e e w e e k lyW a g e : f lo a t H o u r l y P a i d E m p l o y e e ho u r ly R a t e : f l o a t ho u r s W o rk e d : f l o a t
23
n Consider n HoD and Lecturer n One is the specialization of the other n Both can perform a particular service, e.g.
n It is possible that they perform the same task differently n How to implement it?
24
n If the object HoD receives a message to perform an operation which both the and the Lecturer can do, then the method invoked will be the specialized version provided by the class HoD!