OOP - Aggregation, Composition
OOP - Aggregation, Composition
Programming
WEEK 05 Abeeha Sattar
Types of Relationships:
Has – a / has – an
An object contains one or more objects of other classes as members
Association/Aggregation/Composition fall into this category
Is – a / is – an
A class is an extension of another class
Inheritance falls into this category
Association in OOP
Scrollbar
1 1
Window Titlebar
1 1
Menu
1 1 ..
class Engine{};
class Car {
Engine e;
public:
Car() {} //empty default constructor
};
Aggregation in Code (pt. 1)
int main()
{
Person p;
p.isSeated();
Car c(&p);
p.isSeated();
c.setP(&p);
p.isSeated();
c.unloadPassenger();
p.isSeated();
return 0;
}
Mid Term – I Discussion
Fin.
3
: