This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Delegation Vs Aggregation and Composition

 
Gagan Sabharwal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have been going through OOAD by Headfirst. I came across the importance of LSP, the need for Delegation and the importance of Association. The book is very comprehensive. But I still find myself juggling between Aggregation and Composition. I have seen a lot of posts in javaranch regarding the same. However after going through some, I intend to go through some more examples on the aforementioned concepts.

Could please somebody help me with good online articles on the same, which explain the sanctity of association and illustrate a clear difference between aggregation and composition, something which is other than the basic Car, Vehicle kind of examples?

Thanks
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the key elements in the Unified Modeling Language is 'Relationships", e.g. Realization, Generalization, etc.

The Association relationship is used to indicate that two objects interact with each other in some way.

The Aggregation relationship is a type of Association relationship and is used to indicate a whole/part relationship betwen two objects.
This type of relationship applies to designs where the "part" object can exist in other places in the system and does not entirely depend upon
a particular "whole" object for its existence.

The Composition relationship is a type of Assocation relationship and is used to indicate a whole/part relationship between two objects.
This type of relationship applies to designs where the "part" object cannot exist in other places in the system and is entirely dependent upon
a particular "whole" object for its existence.

Hope this helps!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may help: AssociationVsAggregationVsComposition
 
Gagan Sabharwal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you gentlemen!!!
 
Vlad Varnica
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example including getter, setters and associations attribute (e.g. icon with a little arrow) for :
- Association 0..1 to 0..1
- Composition 1 to *
- Aggregation 1 to *

You can't in the java code when reverse engineering a code see the difference between an aggregation or an composition because the only difference is provided by UML.
btw, this association type information is important this is why I think that adding a class diagram to a project will make it clearer
aggregation_with_setters_getters.png
[Thumbnail for aggregation_with_setters_getters.png]
composition_setter_getters.png
[Thumbnail for composition_setter_getters.png]
association_with_setter_getters.png
[Thumbnail for association_with_setter_getters.png]
 
Suresh Gokarakonda
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In one of the design patterns book I am currently reading, the author says "in java language where GC happens automatically there is no difference between aggregation and composition ". Any idea what the author meant by this?
 
Vlad Varnica
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java code is the same for both of them. Aggregation versus Compisition is only an UML information
This is one of the reasons why UML is important
 
Suresh Gokarakonda
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is it different in other languages?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic