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 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 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 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.
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 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 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 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.
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 are closed for "Association, Aggregation, Composition, Abstraction, Generalization, Realization, Dependency".
Now these basic can be easily differentiated, after read this post
Thank you..
Looking forward for your next post…
very nice content to start
Thanks!
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.
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!
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.
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
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
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
Thank You Very Much… It Was Very Helpfull…
Thank you for addressing all relevant items.. little bit more code would be marvelous. still great. CDW
Good explaination mate
Terse explanation of Association, Aggregation and Composition..!!! :) Thanks a lot… :)
Looking forward for your next posts…
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……
jst superb…think u r bst faculty for starters..i bliv in it…”with strong foundationz u can aim for the sky.”
Hi,
The definition given in this site is very clean and neat and simple and very understandable instead of blah..blah…
Cheers !!!
KM
thank you very much for sharing your knowledge. very useful content. I learnt the concept very well to be applied in OOAD.
I was always get confused for these relationship but as you defined these relationship it became easy to understand. Thanks buddy :)
Thanks for these information. Great definition for aggregation n composition
Very nice page.
It contains all required information about association, aggregation, composition.
thanks a lot.
Prabhat.
Nice.. Thank You..
it is simple and very easy to understand
thank you,
simple and understanble…
Thanks a lot
Great Work !!!
Keep going on !!!
All the best !!
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?
thank you for you very clear work joe.
Wow., Awesome work., Thankz,
Keep up the Good work.,
thankz sir , very nice content
thanks much. very useful information
could you please provide some code samples for association, aggregation and other all oops concepts.
Thanks
Varma
multiplicity is no given here :) pls add
thanks
Very easily explained and easy to understand all the definition. Keep it up
simply super….very useful Thanks for posting..
This article is very helpful and well explained. Thanks
Good Artcile. it helps.. Thanks..!
it helped me alot sir………thank u sir
Useful information with good explanation well done Joseph..
Thanks dude.. its really so simple to understand these stuffs…….. really gr8 work.
nice explanation.. thiru
Very Good article… Thank you..
thanks for simple explanation of association, aggregation, composition. Good Work…Thank you..
it is so easy and interesting
explanation also easy for preparing answerssssssssssss
Nice Article Joe..Like very much the way you describe ,Must say Very good Article for the beginners …!!!
Superb Article !!!!!!!!!
Nice Article, Much useful for a beginner
very good explanation on composition and aggregation relationships
Dear sir, I need more explanation and example about abstraction… How to apply in c…? i use data structure linked list concept..
Nice explanation on the topics of association, aggregation and composition with quite undrestandable language.
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
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…
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?
Thanks you very much for share good knowledge for me .
A very good explanation..I never seen before like this type explanation about this concept
very nice artical!!
Very nice explanation about class diagram terms…
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
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
Really simple and excellent explanation. Easy to understand for beginners…!!!
Very good explanation
identify in detail association and aggregation
Nice one
thank you
Thanks..!! M sure your examples gonna help in tomorrows exam.
@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.
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.
Wonderful Job Joe. Keep it up.
really clears the confusion.
Nice way of information.
Thanks………………
Hi,
Superb Explanation sir .
Really good man easy to understand
really helping me a lot….
u r dng a great work.Thank You
awesome
please explain more sir,with example..
Good Summary. Thanks a lot!
A simple class diagram to explain the direction of the relationship would be great, if can be added
nice explanation. very useful. thanks
Great and a very simple way to explain a confusing subject. Thanks a lot for this Post.
GOOD and NICE and SIMPLE Explanation……..
Thanks for your inputs
good site thanks
Thanks very much nice information about Generalization, Aggregation, Association, Composition, Dependency,, only one time i have refereed to it but absolutely i got******
Good explanations….
Nice explanation yaar
Very nice content. I like it. The best site and very comprehensiveness information I ever found.
give me answer plz..
Justifying the statement ,”inheritance is a special case of Generalization”.
Thanks a lot for such an easy explanation. Examples are also easy to understand and correlate.
Thanks a lot Joe, Very Useful information with simple language and good examples.
nice explanation..
Nice Article Joe
I love your blog and find helpful…thanks for your great passion! You people make the world really great!
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.?
very lucid and helpful. thank you.
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”
I Think U are right Hikmat.
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
Could you please share with java code examples.
A implements B is realization
A extends B is generalization
AM I right?
sir…you should use email validation in comment box…..
and your site content is awesome….i loved it….
Sir…it clearly differentiated the terms for a novice programmer.
Thanks!!:) It was really worthy.. Short & to the point.. Clarifying examples played vital role in understanding.. ‘Thanks’ once again..
_Js
Clear explanation with simplicity!
Thanks
Really a useful stuff to understand object relation ship.
Content is very good and the site is also looking so good keep it up sir,…
very helpful and easy understanding
thank u …………
I was screwed in a interview for all these.. thanks for sharing…really good one..
bhiya tussi to cha gaye…
It will be great if you have some real life example on this..
Thanks Kausik
Had confusion with all these terms..your way of explanation is very simple and straight forward..thanks
unclear definitions
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.
This post is very helpfull to understand the basic concept of association and understands the association type aggregation and composition type ….
Thank you…..
could you please explain these association,aggregation,composition and dependancies with a sample scenario with java classes implementation…..
Thankyou
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.”
very good explanation thanks…………..
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
nice explanation for UML easy understanding…Please continue this short of topics
good article for basics
Very Nice and easy explanation.
Thanks Joe.
superbly explained.. :)
Nice explaination
simple to understand…with real life egg
Its really very easy to understand.. Thanks a lot
Very information. thanks
such a nice information .it will help everyone..
Thank you
it was very useful for me
super
Very helpful and easy t understand
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.
Thanks.:) Clearcut definitions. :)
For association, aggregation and composition could you please put real time exmaples with come classes?
Nice work ..
Really helpful to brush up the concepts.Thanks for posting such a nice article.
cool.. :)
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.
Really good article , thanks a lot.
If you can provide the UML examples using symbols(aggregation,composition and generalization) will be more useful.
Can u please explain about abstraction and encapsulation oops concepts
“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++
in ooad(Object Oriented Analysis Design and UML)
1)Is association class same as ordinary classs? Explain with example.
plz send ans
Association: uses a
Aggregation: has a : strong association
Composition: owns a : weak association
Inheritance: is a
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
Hello,
What is Difference between Association and Dependency ?