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

Last modified on September 7th, 2014 by Joe.

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.

Comments on "Association, Aggregation, Composition, Abstraction, Generalization, Realization, Dependency"

  1. Gift vincy says:

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

  2. Rajesh says:

    Thank you..
    Looking forward for your next post…

  3. himanshu says:

    very nice content to start

    Thanks!

  4. Jyotilal says:

    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.

  5. Joe says:

    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!

  6. Prashant S Shivashimpi says:

    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.

  7. swathi says:

    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

  8. Mutayyab Shah says:

    Sir. i m n trouble..if u post full code .which contain aggregation and compostion.then it will be very clear to all of us.according to programing point of view.
    and realy good work u have done.we appriciate ur work…
    plz post full code waiting 4 ur reply

  9. Amit Shekhar says:

    Thanks Joe for the wonderful post. It is really quite useful.Most of the times we tend to get confused with these terms as all sound the same. Few more additions would make it better:
    a) Class diagrams
    b) Code for Aggregation and Composition

  10. Salman Khan says:

    Thank You Very Much… It Was Very Helpfull…

  11. Casper says:

    Thank you for addressing all relevant items.. little bit more code would be marvelous. still great. CDW

  12. Narayan says:

    Good explaination mate

  13. Chetan Jadhav says:

    Terse explanation of Association, Aggregation and Composition..!!! :) Thanks a lot… :)

    Looking forward for your next posts…

  14. RenuNaidu..... says:

    i searched most of the definitions for these association,aggregation and composition…u cleared my doubt …u people are explaining like baby feeding thank you……

  15. Abhijit Boruah says:

    jst superb…think u r bst faculty for starters..i bliv in it…”with strong foundationz u can aim for the sky.”

  16. kamatchi sundaram says:

    Hi,

    The definition given in this site is very clean and neat and simple and very understandable instead of blah..blah…

    Cheers !!!
    KM

  17. Vijay Agalcha says:

    thank you very much for sharing your knowledge. very useful content. I learnt the concept very well to be applied in OOAD.

  18. Sanjay Upadhyay says:

    I was always get confused for these relationship but as you defined these relationship it became easy to understand. Thanks buddy :)

  19. Kareem Afifiy says:

    Thanks for these information. Great definition for aggregation n composition

  20. Prabhat says:

    Very nice page.
    It contains all required information about association, aggregation, composition.
    thanks a lot.
    Prabhat.

  21. viji says:

    Nice.. Thank You..

  22. kondalarao says:

    it is simple and very easy to understand
    thank you,

  23. sambha says:

    simple and understanble…
    Thanks a lot

  24. sadish says:

    Great Work !!!
    Keep going on !!!

    All the best !!

  25. Su says:

    Very nice article. I am facing a unique situation where we have modeled a test case with two compositions between the same two entities. Is this realistic? If so, can you give me a real world example for this?

  26. ray says:

    thank you for you very clear work joe.

  27. KARTHIKEYAN A says:

    Wow., Awesome work., Thankz,
    Keep up the Good work.,

  28. ankana says:

    thankz sir , very nice content

  29. Rajasekhar says:

    thanks much. very useful information

  30. Varma says:

    could you please provide some code samples for association, aggregation and other all oops concepts.

    Thanks
    Varma

  31. Girish Varma says:

    multiplicity is no given here :) pls add

    thanks

  32. Parmod says:

    Very easily explained and easy to understand all the definition. Keep it up

  33. niranjan says:

    simply super….very useful Thanks for posting..

  34. Baravil Barivare says:

    This article is very helpful and well explained. Thanks

  35. pravinth says:

    Good Artcile. it helps.. Thanks..!

  36. mowlika says:

    it helped me alot sir………thank u sir

  37. Ramakrishna Chandragiri says:

    Useful information with good explanation well done Joseph..

  38. Zahid Nasim says:

    Thanks dude.. its really so simple to understand these stuffs…….. really gr8 work.

  39. Thirupathi says:

    nice explanation.. thiru

  40. Anonymous says:

    Very Good article… Thank you..

  41. Kintesh says:

    thanks for simple explanation of association, aggregation, composition. Good Work…Thank you..

  42. shubh says:

    it is so easy and interesting

  43. shubh says:

    explanation also easy for preparing answerssssssssssss

  44. Om Behera says:

    Nice Article Joe..Like very much the way you describe ,Must say Very good Article for the beginners …!!!

  45. Prakash says:

    Superb Article !!!!!!!!!

  46. NextGeneration says:

    Nice Article, Much useful for a beginner

  47. Ramyashree says:

    very good explanation on composition and aggregation relationships

  48. Mani says:

    Dear sir, I need more explanation and example about abstraction… How to apply in c…? i use data structure linked list concept..

  49. Chandraprakash says:

    Nice explanation on the topics of association, aggregation and composition with quite undrestandable language.

  50. Arun K Deo says:

    You mentioned in this article – Abstraction is specifying the framework and hiding the implementation level information. Abstraction never says about hiding anything. Let’s take an Example of Employee with Super class and Manager and Salesman bening subclass of Employee. So if Employee may provide various implentation in common, but can’t have implementation for calculateBonus because this is fully dependet on nature of employee subclass, and hence Employee would have calculateBonus as abstract. So overall, abstraction is isolation of common essentioal behaviour and supress unimportant behaviours. Abstraction never meanse hiding anything. Hiding of implementation from accidental access is Encapsulation.

    Thanks
    Arun Deo

  51. abi says:

    Very nice post.. i have never experienced such
    simple examples for explaining such complex terms like aggregation and composition
    i thought so far.. Keep posting…

  52. CT says:

    Hi, may I seek a clarification about generalization concept. Let’s say I have a two kinds of staff, Manager and Supervisor and both have the same attributes (name,contact number). So, is it possible to say that this has a generalization relationship – Staff as the superclass, Manager and Supervisor as its subclasses althought there’s no difference in terms of the attributes between Manager and Supervisor?

  53. cheng kuyleang says:

    Thanks you very much for share good knowledge for me .

  54. Anonymous says:

    A very good explanation..I never seen before like this type explanation about this concept

  55. mayur bhalekar says:

    very nice artical!!

  56. Arvind kumar says:

    Very nice explanation about class diagram terms…

  57. Imrana Aminu Muhd says:

    Questions
    1. Identify and briefly explain the objectives, classes, method and attributes for a hotel reservation system.
    2. Draw a use case diagram to represent a hotel reservation system.
    3. Draw a class diagram that models hotel reservation system data structure, clearly representing the objects, classes, associations, generalization and aggregations.

    Thanks

  58. Imrana Aminu Muhd says:

    Questions
    1. Identify and briefly explain the objectives, classes, method and attributes for a hotel reservation system.
    2. Draw a use cases diagram to represent a hotel reservation system.
    3. Draw a class diagram that models hotel reservation system data structure, clearly representing the objects, classes, associations, generalization and aggregations.

    Thanks

  59. Subir says:

    Really simple and excellent explanation. Easy to understand for beginners…!!!

  60. siva says:

    Very good explanation

  61. jay says:

    identify in detail association and aggregation

  62. bluepicaso says:

    Nice one
    thank you

  63. Sanchit says:

    Thanks..!! M sure your examples gonna help in tomorrows exam.

  64. Joe says:

    @Sanchit

    I feel very happy when I get to know that my blog helps a student.

    More than anything, I maintain this to help students succeed in their exams / interviews.

  65. Chandra says:

    Good article. One of the questions mentioned above, was related to manager,supervisor and staff. Certainly there is a generalization relationship with Staff as superclass and manager and supervisor classes are subclasses inheriting from Staff. Though attributes could be same in manager and supervisor when it comes behaviour(methods) manager and supervisor classes are specialized with inheriting the generic class i.e., Staff.

  66. TSKarthic says:

    Wonderful Job Joe. Keep it up.

  67. Anonymous says:

    really clears the confusion.

  68. Rohit Ojha says:

    Nice way of information.
    Thanks………………

  69. Pradip Lavania says:

    Hi,

    Superb Explanation sir .

  70. Nikhil says:

    Really good man easy to understand

  71. venky says:

    really helping me a lot….
    u r dng a great work.Thank You

  72. samy says:

    awesome

  73. himanshu says:

    please explain more sir,with example..

  74. YoFo says:

    Good Summary. Thanks a lot!
    A simple class diagram to explain the direction of the relationship would be great, if can be added

  75. priya says:

    nice explanation. very useful. thanks

  76. Rupesh says:

    Great and a very simple way to explain a confusing subject. Thanks a lot for this Post.

  77. SAGAR_D says:

    GOOD and NICE and SIMPLE Explanation……..

  78. sabarish says:

    Thanks for your inputs

  79. sourabh singhai says:

    good site thanks

  80. Mohammad Arif says:

    Thanks very much nice information about Generalization, Aggregation, Association, Composition, Dependency,, only one time i have refereed to it but absolutely i got******

  81. VVV says:

    Good explanations….

  82. Gajendra says:

    Nice explanation yaar

  83. zeeshan says:

    Very nice content. I like it. The best site and very comprehensiveness information I ever found.

  84. Ravi says:

    give me answer plz..
    Justifying the statement ,”inheritance is a special case of Generalization”.

  85. SanjayK says:

    Thanks a lot for such an easy explanation. Examples are also easy to understand and correlate.

  86. Ganesh says:

    Thanks a lot Joe, Very Useful information with simple language and good examples.

  87. Anonymous says:

    nice explanation..

  88. Pavan says:

    Nice Article Joe

  89. Abdul Hadi Ibrahimi says:

    I love your blog and find helpful…thanks for your great passion! You people make the world really great!

  90. Ganesh says:

    ijust hv a doubt about composition ,as a example “A circle is composed of points”.
    then i think points are exist without circle ,,but according to u points r not exist without circle ..plz explain.?

  91. nitish says:

    very lucid and helpful. thank you.

  92. Hikmat Jaber says:

    In defining the Composition in top of page, I think the sentence should be
    “…, if the container object cannot exist without the existence of contained object, then it is called composition”
    instead of “…, if the contained object cannot exist without the existence of container object, then it is called composition”

  93. Priyabrat says:

    I Think U are right Hikmat.

  94. Pratik Jain says:

    Nice article.
    Adding some example, hope till will support the article.
    There are four kinds of Class relationships

    Association: uses a
    Ex:a Class Man uses a Class Pen
    Aggregation: has a
    Ex:a Class Man has a Class Car ( Car is still there when Man die )
    Composition: owns a
    Ex:a Class Man owns a Class Heart ( When Man die, Heart die )
    Inheritance: is a
    Ex:a Class Man is a Class Human ( Man is a Human )
    A relationship between classes of objects

    Inheritance>Composition>Aggregation>Association

  95. manojbharal says:

    Could you please share with java code examples.

    A implements B is realization
    A extends B is generalization

    AM I right?

  96. Parshant says:

    sir…you should use email validation in comment box…..
    and your site content is awesome….i loved it….

  97. Vijay Arige says:

    Sir…it clearly differentiated the terms for a novice programmer.

  98. Jigar says:

    Thanks!!:) It was really worthy.. Short & to the point.. Clarifying examples played vital role in understanding.. ‘Thanks’ once again..
    _Js

  99. Minesh says:

    Clear explanation with simplicity!
    Thanks

  100. Vijay says:

    Really a useful stuff to understand object relation ship.

  101. Hakkim says:

    Content is very good and the site is also looking so good keep it up sir,…

  102. jpnaidu says:

    very helpful and easy understanding

  103. Anonymous says:

    thank u …………

  104. manikesh says:

    I was screwed in a interview for all these.. thanks for sharing…really good one..

  105. Anonymous says:

    bhiya tussi to cha gaye…

  106. Kausik says:

    It will be great if you have some real life example on this..

    Thanks Kausik

  107. Anonymous says:

    Had confusion with all these terms..your way of explanation is very simple and straight forward..thanks

  108. Anonymous says:

    unclear definitions

  109. Ganesh says:

    Dependency explanation is need to be amended as follows.

    Dependency is a weaker form of relationship which indicates that one class depends on another because it uses it at some point of time. One class depends on another if the latter is a parameter variable or local variable of a method of the former. This is different from an association, where an attribute of the former is an instance of the latter.

  110. Ajay Shah says:

    This post is very helpfull to understand the basic concept of association and understands the association type aggregation and composition type ….

  111. durga says:

    Thank you…..
    could you please explain these association,aggregation,composition and dependancies with a sample scenario with java classes implementation…..

  112. jyoti says:

    Thankyou

  113. Yuri says:

    Hi, Joe!
    Thank you for your explanations!
    But… you write: “A book cannot exist without a library and therefore its a composition.”
    I think more correctly would be as follows:
    “A library cannot exist without book and therefore it’s a composition.”

  114. dheeraj says:

    very good explanation thanks…………..

  115. shashikant pandit says:

    earlier i confused to understand about these topic .but by the God i found your site, and understood these all topics with in few moments.

    nice site

  116. Anonymous says:

    nice explanation for UML easy understanding…Please continue this short of topics

  117. Anonymous says:

    good article for basics

  118. Abhijeet says:

    Very Nice and easy explanation.

    Thanks Joe.

  119. Gaurav says:

    superbly explained.. :)

  120. Anonymous says:

    Nice explaination

  121. Anonymous says:

    simple to understand…with real life egg

  122. Priya says:

    Its really very easy to understand.. Thanks a lot

  123. js says:

    Very information. thanks

  124. vandu says:

    such a nice information .it will help everyone..

  125. Hamed Mirzaei says:

    Thank you

    it was very useful for me

  126. archana says:

    super

  127. Anonymous says:

    Very helpful and easy t understand

  128. Jatinder says:

    Indeed this is a very good post.
    If i have understood correctly,then will it be ok to say that a child in a mother’s womb is an example of composition and after birth,a mother-child relation can be called aggregation.
    Request all learned to please correct me if i have understood incorrectly.

  129. Girish says:

    Thanks.:) Clearcut definitions. :)

    For association, aggregation and composition could you please put real time exmaples with come classes?

    Nice work ..

  130. pradeep says:

    Really helpful to brush up the concepts.Thanks for posting such a nice article.

  131. sarang says:

    cool.. :)

  132. Venkat says:

    Hi Joe, very nice explanation.
    I just got doubt about the sentence in “Generalisation” , you wrote as – Common structure and behaviour are used from the specializtion to the generalized class.

    or it should be as below.

    Common structure and behaviour are used from the generalized to the specializtion class.

    Correct me on this please.

  133. Nagarjuna says:

    Really good article , thanks a lot.

    If you can provide the UML examples using symbols(aggregation,composition and generalization) will be more useful.

  134. Prakash says:

    Can u please explain about abstraction and encapsulation oops concepts

  135. furry says:

    “Suppose we have implemented a scenario and we used aggregation in it, after some time we realize that use of aggregation is not a correct choice, now we want to use composition instead of aggregation. Can we replace composition with aggregation? At which phase(s) these changes are required? Justify your answer with solid reasons. ”

    sir this question is related by C++

  136. thakkar komal says:

    in ooad(Object Oriented Analysis Design and UML)

    1)Is association class same as ordinary classs? Explain with example.

    plz send ans

  137. Amitabha Roy says:

    Association: uses a
    Aggregation: has a : strong association
    Composition: owns a : weak association
    Inheritance: is a

  138. Swapnil says:

    U Say ‘ if the contained object cannot exist without the existence of container object, then it is called composition.’–>with example Library–>Books
    With your definition ‘Books can not exists without Library’..How’s this ? ..or is it the other way round ‘Library can not exists without Books’??
    I am damn confused?
    Please please help.Thanks

  139. Ali says:

    Hello,

    What is Difference between Association and Dependency ?

Comments are closed for "Association, Aggregation, Composition, Abstraction, Generalization, Realization, Dependency".