Lecture 15 Oop
Lecture 15 Oop
Association
Relationship where all object have their own lifecycle and
there is no owner.
Ex: Airplane and Passengers.
No ownership between the objects and both
have their own lifecycle. Both can create and
delete independently.
Association
• Association is a relationship between two objects.
Output
Task
• Write a C++ program to create two classes student and Teacher. Use
aggregation to solve it.
Composition
Output
Task
• Write a C++ program to create two classes A and B.
18
Representing Aggregation/Composition in Classes
An aggregation / composition relationship is usually represented as a data field in the aggregated class.
19
Inheritance(Generalization)
• The capability of a class to derive properties and characteristics from
another class is called Inheritance.
• The derived class now is said to be inherited from the base class.
• When we say derived class inherits the base class, it means, the derived
class inherits all the properties of the base class, without changing the
properties of base class and may add new features to its own.
• These new features in the derived class will not affect the base class. The
derived class is the specialized class for the base class. The base class is the
generalized class for the derived class.
Inheritance
• Sub Class: The class that inherits properties from another class is
called Subclass or Derived Class.
• Super Class: The class whose properties are inherited by a subclass is
called Base Class or Superclass.
27