Aggregation vs Composition

Aggregation is a type of association in which the relationship between two objects is a part or whole.  This type of relationship is loosely coupled and an object can survive alone also. You can say they have the “has-a” relationship.  The aggregation is depicted as a empty diamond in UML diagram. For example, a student can have professor object but still the student can work independently.  In other terms we can say student object has a professor object. But student object can be independently accessed. If you delete the professor object, student object can still survive.

Composition on the other hand is a type of association in which the relationship between two objects is tightly coupled. One object depends on the other and cannot survive alone. The objects have a strong “has-a” relationship with the other object.  You can say one object is the part of the other object. The composition is depicted as fill diamond in UML diagram. For example, a house object is composed of room object. If you delete the house object, room object will have no existence. So, the room object requires a house object.

Advertisements

B.E in Electronics and Telecommunications from Raipur, Chhattisgarh. Currently working on Microsoft's .NET and SQL Server Technology

Posted in Object Oriented Programming, Unified Modeling Language

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: