Book a Demo

Author Topic: Aggregation/Composite in class diagram question  (Read 4980 times)

bslatner

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Aggregation/Composite in class diagram question
« on: August 28, 2007, 05:30:27 pm »
Have a class "Order" that is composed of many class "Worksheet" objects. The "Worksheet" objects need pointers back to their parent "Order".

I'm having a real tough time getting the proper C# generated for this. I set up the composite relation correctly. I set the default collection class to List<#TYPE#>. And I set the source role name to "Worksheets". When I generate code, the Order class has a nice member called "Worksheets" of type List<Worksheet>. Exactly as intended.

Where I'm having trouble is in the link back to the parent. No amount of fiddling with the Target Role tab (and the association directly) has been able to get EA to generate a member in the Worksheet class that points back to the Order.

Does EA support this kind of link automatically, or do I need to add it to the code generation templates?

Thanks,
Bryan

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Aggregation/Composite in class diagram questio
« Reply #1 on: August 28, 2007, 07:01:04 pm »
You'll need to use a bi-directional association (with no aggregation or composition).  EA will not generate the member for the aggregate end.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Aggregation/Composite in class diagram questio
« Reply #2 on: August 28, 2007, 09:45:00 pm »
Hmm, from a theoretical point I do not agree with this.
I you have modeled an aggregation or composition then there was a reason to do so.
Whether or not to create a reference to the other part of an association should ONLY be based on the directionality (is that a word ???). The fact that an association is a composition or aggregation has nothing to do with that.
I may be a questionable design decision to have a bi-directional composition, but that should be entirely up to the designer. EA should not make assumptions about that.

Martin Terreni

  • EA User
  • **
  • Posts: 672
  • Karma: +0/-0
  • Sorry, I can't write
    • View Profile
Re: Aggregation/Composite in class diagram questio
« Reply #3 on: August 28, 2007, 09:53:38 pm »
I'm not sure I'm up to date with this issues any more or how I remember the theory, but I do remember having to work out this same problems for the design and not making development managers so happy about it...
Recursion definition:
If you don’t understand the definition read "Recursion definition".

bslatner

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Aggregation/Composite in class diagram questio
« Reply #4 on: August 29, 2007, 03:11:13 pm »
Quote
Hmm, from a theoretical point I do not agree with this.
I you have modeled an aggregation or composition then there was a reason to do so.
Whether or not to create a reference to the other part of an association should ONLY be based on the directionality (is that a word ???). The fact that an association is a composition or aggregation has nothing to do with that.
I may be a questionable design decision to have a bi-directional composition, but that should be entirely up to the designer. EA should not make assumptions about that.


Well, it's certainly possible I'm using the wrong relationship for what I want to do. I'm not a UML guru by any stretch. Perhaps a vanilla, bi-directional association is what's called for here. But composition seemed like the proper relationship at the time, given the nature of the objects. An "Order" is composed of 1..n "Worksheet", and all "Worksheet" are destroyed when the "Order" is destroyed. That seems like composition. But on the other hand, "Worksheet" need to be able to send messages (and read data from) their parent "Order"...so maybe composition is not appropriate. Any thoughts on this are greatly appreciated.

Thanks,
Bryan

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Aggregation/Composite in class diagram questio
« Reply #5 on: August 29, 2007, 09:45:09 pm »
from UML formal superstructure 2.0:
Quote
An association may represent a composite aggregation (i.e., a whole/part relationship). Only binary associations can be
aggregations. Composite aggregation is a strong form of aggregation that requires a part instance be included in at most
one composite at a time. If a composite is deleted, all of its parts are normally deleted with it. Note that a part can (where
allowed) be removed from a composite before the composite is deleted, and thus not be deleted as part of the composite.
Compositions define transitive asymmetric relationships, their links form a directed, acyclic graph. Composition is
represented by the isComposite attribute on the part end of the association being set to true.

What I remember from previous discussions about the subject, the mean criteria to decide wether or not to use a composition are:
- the multiplicity on the whole part is always maximum 1. I.e a part can only belong to one whole at a time.
- the part is deleted when the whole is deleted.

The OMG definition adds another one by defining it to be an "acyclic graph". I guess this means that an element in a composition cannot be a part of itself.
I think the "directed" part of the "directed acyclic graph" means that there one end of the association defined as "composite" and the other end as "part", but I'm not really sure about this. Maybe the directed part is about the navigability. Any other thoughts?

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Aggregation/Composite in class diagram questio
« Reply #6 on: August 29, 2007, 11:18:16 pm »
Quote
I think the "directed" part of the "directed acyclic graph" means that there one end of the association defined as "composite" and the other end as "part", but I'm not really sure about this.
Because composition is about meronymy (the relationship between the whole and the part), the result is that the graph is directed.  (Not t'other way 'round).

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

bslatner

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Aggregation/Composite in class diagram questio
« Reply #7 on: August 30, 2007, 03:08:33 pm »
Quote
Because composition is about meronymy (the relationship between the whole and the part), the result is that the graph is directed.  (Not t'other way 'round).

HTH,
Paolo


Paolo,

I've never heard the word "meronymy" before. Thank you for introducing it to me  :)

bslatner

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Aggregation/Composite in class diagram questio
« Reply #8 on: August 30, 2007, 03:09:53 pm »
Quote
- the multiplicity on the whole part is always maximum 1. I.e a part can only belong to one whole at a time.
- the part is deleted when the whole is deleted.


Based on this, it definitely seems like "composite" is what I want.

I'll let my brain chew on "directed, acyclic graph" for a while   ;D

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Aggregation/Composite in class diagram questio
« Reply #9 on: August 30, 2007, 04:13:38 pm »
Quote

Paolo,

I've never heard the word "meronymy" before. Thank you for introducing it to me  :)
Search the UML category (an and some others) in this forum for some discussion on the topic (meronymy) - including some worked examples.

HTH,
Paolo
(Stick wid' me kid, 'n I'll improve your vocabulary in no time...  ;D)
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!