Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BJO - Relationships b/w objects ??????

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jacquie,

I am little confuse between Dependencies, Association, Aggregation, Composition etc.

Aggregation is Has-a relationship.

Composition is strongest form of Aggregation.

Association is stronger form of Aggregation.

What is this all...

Could you please explain me these all with help of real example and code. Does BJO covers it??

Thanks a lot.
[ July 13, 2005: Message edited by: rathi ji ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See http://faq.javaranch.com/view?AssociationVsAggregationVsComposition
 
Jacquie Barker
author
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's how I address that topic in BJO (paraphrasing):

===

An association is a relationship between two classes A and B, implemented in code as follows:

one-to-one -- we provide A with a reference to an object of type B as an attribute (and vice versa, if we want the association to be bi-directional)

one-to-many -- if there is one instance of A for many instances of B, we equip A with a Collection of references to B as an attribute

many-to-many -- both A and B wind up with a Collection of the other as an attribute (if bi-directional)

===

Aggregation -- essentially an association that implies containment -- e.g., "has a", "is part of", "belongs to", etc. Aggregations are represented in code identically to associations, as discussed above.

===

Composition -- a strong form of aggregation in which the "contained" object ceases to exist if the "containing" object ceases to exist. Again, coded in the same way that associations/aggregations are coded, but extra work must be done programmatically to make sure that the contained object is "snuffed" when the containing object is.

===

I hope this helps ...
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Jacquie,
It was very clear + short and sweet description .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic