• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Delegation Vs Aggregation and Composition

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may help: AssociationVsAggregationVsComposition
 
Gagan Sabharwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you gentlemen!!!
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is it different in other languages?
reply
    Bookmark Topic Watch Topic
  • New Topic