PDA

View Full Version : What is Aggregation in OOP?



saneha
04-29-2011, 08:43 AM
What is Aggregation in OOP?

Vuhelper
04-29-2011, 08:44 AM
Aggregation is a relationship between the container and contained object. Aggregation is a weaker relationship, because aggregate object is not a part of the container, and aggregate object can exist independently. Aggregation is implemented in c++ by using a pointer or reference to an object that is created inside a class.
Real world example:
A single teacher can not belongs to multiple departments, but if we delete the department teacher object will not destroy.
Example:
class Student{
--------------
};
class Teacher: public Student {
-------------------
Student * name; //Here is aggregation relationship b/w Student and Teacher class
-------------------
-------------------