• 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

UML composition doubt

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am in doubt with the following UML syntax. Could you please put your comment:-

I have the following classes:
  • Customer
  • ContactInfo
  • Address


  • Now Customer has Composition realtionship with ContactInfo and ContactInfo has composition relation with Address

    So, in my UML diagram do I have to show like in Option A OR
    in Option B

    ---------
    Option A |
    ---------

    . . . . .. . . Compostion . . . . . . . . . Compostion
    Customer----------------->ContactInfo------------------->Address



    -------------
    Option B |
    -------------


    . . . . . .. . Compostion
    Customer----------------->ContactInfo------------------->Address



    That is my doubt is : as Cutomer has Composition relation with ContactInfo, is it implicit that ContactInfo has composition relation with Address i.e is it okay to show as in Option B OR I have to show Explicitly as show in Option A

    Forgive me if it is too easy question.

    Regards
    Sonal
    [ May 22, 2006: Message edited by: Sonal Ray ]
     
    Ranch Hand
    Posts: 904
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,

    Before answering your question I'd just like to point a few things out. You
    are probably aware of the following, but I just want to make sure:

    UML composition notation: Part----<#>Whole
    UML aggregation notation: Part----<>Whole

    Aggregation and compositions are both associations. The difference between
    the two is, that in an composition it's Parts lifetime is controlled by
    the Whole.


    Your question:

    Yes, I think you should show it explicit.

    /Svend Rost
     
    Sheriff
    Posts: 7001
    6
    Eclipse IDE Python C++ Debian Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Are you sure that (for example) contactInfo ---> address is really a composition (or even the slightly weaker aggregation) relationship rather than just an association?

    You are implying that the address is somehow part of the contact details, but this says to me that (for example) if you have more than one customer with the same address details, your system will be forced to contain more than one copy of those address details.

    Perhaps a better system would decouple the idea of an address from the idea of a customer (much as they are in the 'real world' - I don't carry my home around with me, and neither does my wife ), linked by a more general association ("lives at" "delivery address", "invoice address" etc.).

    I realise that this has not actually answered your question, but because of this knd of issue I am always wary of leaping to soon to details such as whether a particular association is composition, aggregation, or something else. I tend to leave such information off my diagrams unless it's really necessary to convey a particular point.
     
    Sonal Ray
    Ranch Hand
    Posts: 56
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Svent.

    Frank , I got the Clue.... . Thank u!
     
    Ranch Hand
    Posts: 120
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Frank,
    Would you please explain/differentiate Aggregation and Composition?

    What I know so far is :

    Aggregation:

    Lets take an example of a Class Vehicle.

    Class Vehicle{
    Engine engineRef;
    Wheels wheelsRef;
    // And other member data

    //Member methods

    }

    Here the Class Vehicle has references to other Objects. In other words, there are some "has-a" relationships with other other objects. This Association is called Aggregation.

    Composition :

    With respect to Com[position, I guess it is some special case of Aggregation. Except for this, I am a novice to this concept.

    I appreciate your help .
     
    Frank Carver
    Sheriff
    Posts: 7001
    6
    Eclipse IDE Python C++ Debian Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    We have a FAQ on this very topic: http://faq.javaranch.com/view?AssociationVsAggregationVsComposition

    Please take a look, and if you have any further questions, please feel free to ask.
     
    Greenhorn
    Posts: 24
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,

    Aggregation can be represented as follows:

    public class Car{
    private Wheel wheels[];

    public Car(Wheel w1,Wheel w2,Wheel w3,Wheel w4){
    wheels[0] = w1;
    wheels[1] = w2;
    wheels[2] = w3;
    wheels[3] = w4;
    }

    }

    Composition can be represented as follows:

    public class Company{
    private Department dept[];

    public Company(){
    dept[0] = new Department();
    dept[1] = new Department();
    dept[2] = new Department();
    dept[3] = new Department();
    }

    }


    Regards,
    Srikanth
     
    (instanceof Sidekick)
    Posts: 8791
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    In Java code they're both just associations, eg A has a member variable of type B. To discern the difference in code you'd have to look around for scope and life cycle responsibilities.

    If B is a wholly owned composed part of A you'd like B to "go away" when A does. In Java A cannot "destroy" B. We only have GC. If A ever lets a reference to a composed part out in public it no longer has any control over B's life span, as some other object could hold a reference and provide navigation to B forever.

    What are you really trying to tell somebody when you model a composition relationship? What behaviors do you mean to enforce or prohibit?
     
    Ever since I found this suit I've felt strange new needs. And a tiny ad:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic