Professional Documents
Culture Documents
DAY- 2
-K. Indhu
GOALS
• Define Objects Respond to Messages,
• Define OOP concepts-
– ENCAPSULATION,
– INFORMATION HIDING (ABSTRACTION),
– CLASS HIERARCHY,
– INHERITANCE,
– POLYMORPHISM.
• Define Object’s Relationships & Associations
– CLIENT-SERVER ASSOCIATION,
– AGGREGATION,
– GENERALIZATION
13-DEC-13 K. INDHU 2
OBJECTS RESPOND TO MESSAGES
• Objects perform operations (or) methods (or) actions, in
response to messages.
• For example, you may communicate with your computer by
sending it a message from hand-help controller like mouse
or keyboard.
• MESSAGES ESSENTIALLY ARE NON-SPECIFIC FUNCTION
CALLS.
• Different Objects can respond to different messages.
– CAR stops()(Method) by PUTTING BRAKE(Message)
– 5 multiply()(Method) by SENDINGMULTIPLY-Message
– Employee GetsPayroll()(Method) by
SENDINGCOMPUTEPAYROLL-Message
13-DEC-13 K. INDHU 3
OBJECTS RESPOND TO MESSAGES
• It is the receiver’s responsibility to respond to a message in an
appropriate manner.
•
It gives a great deal of flexibility, since different objects can respond to
same message in different ways. This process is known as
Polymorphism.
13-DEC-13 K. INDHU 4
INFORMATION-HIDING (ABSTRACTION)
• Information hiding is a principle of hiding internal
data and procedures of an object and exposing only
those features that are essential to the end-user.
13-DEC-13 K. INDHU 5
ENCAPSULATION
• Data Binding is called as Encapsulation.
• Encapsulation is a protection mechanism with public,
private and protected members.
• Public members( member-data & member-functions) can
be accessed from anywhere.
• Private members are accessible only within a class.
• Protected members can be accessed only from sub-classes.
• AN OBJECT IS SAID TO ENCAPSULATE DATA & PROGRAM.
• This means that the user cannot see the inside of the
object “capsule”, but can use the object by calling the
object’s methods.
13-DEC-13 K. INDHU 6
CLASS HIERARCHY
• An object-oriented system organizes classes into subclass-super
hierarchy.
• At the top of the hierarchy are the most general classes and at the
bottom are the most specific.
• A subclass inherits all of the properties and methods (procedures)
defined in its superclass.
13-DEC-13 K. INDHU 7
INHERITANCE- programming by extension
• Inheritance is the property of object-oriented systems that allows
objects to be built from other objects.
• The parent class is called as base class or super class. The child class is
called as derived class or sub class.
13-DEC-13 K. INDHU 8
INHERITANCE- programming by extension
13-DEC-13 K. INDHU 9
DYNAMIC INHERITANCE
• What do you mean by Dynamic Inheritance?
– Dynamic Inheritance refers to the ability to add, delete,
or change parents from objects (or classes) at runtime.
13-DEC-13 K. INDHU 10
MULTIPLE INHERITANCE
• OO systems permit a class to inherit from more than
one super-class.
• This kind of inheritance is referred to as multiple
inheritance.
• Some OOPS languages like C++ supports Multiple
Inheritance.
• Few OOPS languages like C# does not support
Multiple Inheritance.
• For example utility vehicle inherits from Car and
Truck classes.
13-DEC-13 K. INDHU 11
MULTIPLE INHERITANCE
13-DEC-13 K. INDHU 12
POLYMORPHISM
• Polymorphism means that the same operation may behave
differently on different classes.
• Polymorphism means “having many forms”.
• It allows different objects to respond to the same message in
different ways, the response specific to the type of the object.
• For example, ComputePayroll() method of Manager-Class
computes the payroll of Manager & ComputePayroll() method
of Worker-Class computes the payroll of Worker.
• Real Time Example, Water exhibits Polymorphism:-
– It is ICE in SOLID form,
– It is WATER in LIQUID form,
– It is VAPOUR in GAS form.
13-DEC-13 K. INDHU 13
POLYMORPHISM
• There are 2 types of Polymorphism:-
– Compile Time Polymorphism
– Run Time Polymorphism
• In Compile Time Polymorphism, revealing of which form of
operation to be invoked- this decision is made at Compile
Time.
• In Run Time Polymorphism, revealing of which form of
operation to be invoked- this decision is made at Run Time.
13-DEC-13 K. INDHU 14
ASSOCIATION BETWEEN CLASSES
• When a relationship exists between two classes of two
objects or between a class and an object, then ASSOCIATION
(or) RELATIONSHIP is said to exist between the two.
• For example a pilot can fly planes.
13-DEC-13 K. INDHU 15
ASSOCIATION BETWEEN CLASSES
• Factors to be considered in Association:-
– Association(Relationship) name,
– Direction of Association
• Association are bidirectional that means they can traversed in both direction.
– Cardinality of Association
– specifies how many instances of one class may relate to one or more
instances, of the associated class.
• One To One
– One Student HAS One RegistrationNo.
• One To Many (*)
– One Student LEARNS FROM Many Professors
• Many (*) To One
– Many Students STUDIES IN One Class
• Many (*) To Many (*)
– Many Students LEARNS FROM Many Professors
13-DEC-13 K. INDHU 16
CLIENT – SERVER ASSOCIATION
• A special form of association is a consumer-
producer relationship, also known as a client-
server association or a use relationship.
• The Consumer – Producer relationship can be
viewed as one-way interaction.
• One object request the service of another object.
• The object that makes the request is the consumer
/ client. The object that receives the request and
provides the service is the producer / server.
13-DEC-13 K. INDHU 17
AGGREGATION
• When one object contains [or has a] another
object, the relationship between both the
objects is called as Aggregation.
• Object Containment is called as Aggregation.
• Aggregation describes a “has a” relationship.
One object is a part of another object.
A CAR HAS WHEELS.
• As in above example, a car object is an
aggregation of engine, seat, wheels, etc. .
13-DEC-13 K. INDHU 18
AGGREGATION
13-DEC-13 K. INDHU 19
GENERALIZATION
• This is also called as “is a” relationship.
• The other synonym of Generalization is
Inheritance.
A CAR IS A VEHICLE
A DOG IS AN ANIMAL
A TEACHER IS A PERSON
13-DEC-13 K. INDHU 20
HAPPY LEARNING!!!