• 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

Doubt in Relationship of Class Diagram

 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now, i'm create Class Diagram in my project, But i have some doubt about relationship of Class Diagram :: association, composition and aggregation .

Please descripe about three relationship of class diagram.

What does each relationship mean ?
When to use each relationship?


Thank you.
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Composition (A<>-B) means A HAS AND OWNS B. In example car HAS AND OWNS wheels (unless of course you want your wheel objects to stick around without a car).

Aggregation (A<>-B) means A refers to B but is not owner of B. In example car REFERS to owner, but the car owner is not a part of the car itself.


Usually A controls lifetime of B in composition relationship. This is easier to understand in C++, when you have to create AND destroy objects.

Association is IMO generic link when you can't use any other type of link but still there is some kind of relationship.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Vladas Razas .

And IF i changed something in B , then A of each relationship will change or not? (A depandent B or not ??)
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, somkiat, for Composition, B is dependent of A... If you destroy A, B will also be destroyed... But for Association and Aggregation, the classes are independent...

Just my 2 cents...
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's clear,

Thank you very for all answer.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a very frequently asked question. Consequently we have an entry in our FAQ: http://faq.javaranch.com/view?AssociationVsAggregationVsComposition
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for good link.
 
author
Posts: 608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At http://www.agilemodeling.com/style/classDiagram.htm#_Toc855100 and below I post guidelines regarding the various relationships (assocation, aggregation, and composition).

Frankly, my advice is to not worry all that much about what type of relationship it actually is. For example, one poster said that with composition you always delete the part but not with association or aggregation. Many people would disagree with that, and say that you would automatically do that as well for aggregation too. The point is that different people have different styles of working, so if you choose to impart meaning into what the diamonds represent then everyone on the team had better agree to a common set of modeling style guidelines.

- Scott
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic