• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

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
 
Oh the stink of it! Smell my tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic