Association, Aggregation, Composition, Abstraction, Generalization, Realization, Dependency

June 26th, 2010

These terms signify the relationships between classes. These are the building blocks of object oriented programming and very basic stuff. But still for some, these terms look like Latin and Greek. Just wanted to refresh these terms and explain in simpler terms.

Association

Association is a relationship between two objects. In other words, association defines the multiplicity between objects. You may be aware of one-to-one, one-to-many, many-to-one, many-to-many all these words define an association between objects. Aggregation is a special form of association. Composition is a special form of aggregation.

Example: A Student and a Faculty are having an association.

Aggregation

Aggregation is a special case of association. A directional association between objects. When an object ‘has-a’ another object, then you have got an aggregation between them. Direction between them specified which object contains the other object. Aggregation is also called a “Has-a” relationship.

Composition

Composition is a special case of aggregation. In a more specific manner, a restricted aggregation is called composition. When an object contains the other object, if the contained object cannot exist without the existence of container object, then it is called composition.

Example: A class contains students. A student cannot exist without a class. There exists composition between class and students.

Difference between aggregation and composition

Composition is more restrictive. When there is a composition between two objects, the composed object cannot exist without the other object. This restriction is not there in aggregation. Though one object can contain the other object, there is no condition that the composed object must exist. The existence of the composed object is entirely optional. In both aggregation and composition, direction is must. The direction specifies, which object contains the other object.

Example: A Library contains students and books. Relationship between library and student is aggregation. Relationship between library and book is composition. A student can exist without a library and therefore it is aggregation. A book cannot exist without a library and therefore its a composition. For easy understanding I am picking this example. Don’t go deeper into example and justify relationships!

Abstraction

Abstraction is specifying the framework and hiding the implementation level information. Concreteness will be built on top of the abstraction. It gives you a blueprint to follow to while implementing the details. Abstraction reduces the complexity by hiding low level details.

Example: A wire frame model of a car.

Generalization

Generalization uses a “is-a” relationship from a specialization to the generalization class. Common structure and behaviour are used from the specializtion to the generalized class. At a very broader level you can understand this as inheritance. Why I take the term inheritance is, you can relate this term very well. Generalization is also called a “Is-a” relationship.

Example: Consider there exists a class named Person. A student is a person. A faculty is a person. Therefore here the relationship between student and person, similarly faculty and person is generalization.

Realization

Realization is a relationship between the blueprint class and the object containing its respective implementation level details. This object is said to realize the blueprint class. In other words, you can understand this as the relationship between the interface and the implementing class.

Example: A particular model of a car ‘GTB Fiorano’ that implements the blueprint of a car realizes the abstraction.

Dependency

Change in structure or behaviour of a class affects the other related class, then there is a dependency between those two classes. It need not be the same vice-versa. When one class contains the other class it this happens.

Example: Relationship between shape and circle is dependency.

Thank you..
Looking forward for your next post…

Rajesh on June 28th, 2010 7:12 am

very nice content to start

Thanks!

himanshu on June 28th, 2010 7:24 am

Now these basic can be easily differentiated, after read this post

Gift vincy on June 28th, 2010 12:12 pm

Very helpful. Thanks.

fixxer on June 29th, 2010 10:22 pm

Nice article. Explanation the concepts clearly.Thank you

ashok on June 29th, 2010 11:22 pm

Good article. Thanks.

Gajanan on June 30th, 2010 3:38 am

Very nice and easy to understand in a simple definitions.

Ravindra Sareddy on July 1st, 2010 7:59 am

It will be still good iy you give examples with code also.

Anonymous on July 1st, 2010 3:22 pm

Thank you all. I will try to update the post with sufficient java source code examples soon.

Joe on July 1st, 2010 5:58 pm

thanks for posting.please update Java with ibatis configuration it is helpful to us
thanks in advance

Anonymous on July 1st, 2010 9:57 pm

An example for aggregation is missing and it could be like:

A car has a stereo system.A car can exist without a stereo system. There exists aggregation between car and stereo.

Jyotilal on July 13th, 2010 5:59 pm

Thanks Jyotilal for the aggregation example. Actually its otherway around.

A car has a stereo system. A stereo system can exist without a car. There exists aggregation between car and stereo.

Don’t go too technical into electronics and say a car stereo needs a car. Just for an example!

Joe on July 14th, 2010 5:13 am

Really very good and straight forward description about the Association, Aggregation, Composition, Abstraction, Generalization, Realization, Dependency. Thank you so much..

Its very handy too..

Cheers,
Prashant.

Prashant S Shivashimpi on July 20th, 2010 11:02 am

Superb Example.

Keep Posting Joe

Harish Dewangan on July 29th, 2010 10:46 am

Thanks! Very nice explanation.

Lingaraj on August 1st, 2010 9:27 am

Thanks for helping……………

Dhananjay..........aec on August 1st, 2010 4:51 pm

Good explain…

Muthukumar on August 3rd, 2010 4:52 am

Hi ,

thnaks for that information.

but i think i havnet understand that last.(Dependency)
does it comes with arrow or just —- lines. pls post me

swathi on August 15th, 2010 12:37 pm





hidden and gravatar enabled.