Author Topic: Association or aggregation?  (Read 1686 times)

Christopher_Wells

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Association or aggregation?
« on: June 22, 2005, 09:34:21 am »
Let's say I have source code which looks like this:

class Foo
{
 Bar m_bar;
}

class Bar
{
}

If I reverse-engineer this, then EA models it as an "Association" whose source is Foo and whose target is Bar.

But if I model this by hand, I thought I should model it as an "Aggregation" whose source is Bar and whose target is Foo?

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 6533
  • Karma: +126/-95
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Association or aggregation?
« Reply #1 on: June 22, 2005, 09:53:55 am »
Hi Christopher,

I don't want to enter the debate yet (It's nearly 1 am  here and I've just re-installed XP on my daughter's computer for the 4th time tonight  :'()

But as an experiment (and to provide you with some immediate feedback) create a couple of examples using  different types of Association and Aggregations (in particular use an Association with aggregation set vs Aggregation) and forward engineer.  Compare the results.   Reverse engineer (to a new model).  Resynchronise to the original model.  

Compare and contrast...  You should have an interesting time...  let us knowif you find anything interesting. ;)

HTH,

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

thomaskilian

  • Guest
Re: Association or aggregation?
« Reply #2 on: June 22, 2005, 01:58:47 pm »
You're a mean guy ;D. But after that session I'd be in the same mood :P

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 6533
  • Karma: +126/-95
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Association or aggregation?
« Reply #3 on: June 22, 2005, 03:21:44 pm »
Quote
You're a mean guy ;D. But after that session I'd be in the same mood :P

Two points, Sir Thomas  ;D,

1) Mean, me?  I already did the test within he first week I had EA.  I just couldn't remember the outcome. ::)  I've already made my decision as to how I model aggregations...  Now I've woken up again, I still can't remember the outcome (getting old)! ;D  Got to install Office now - or someone can't do their homework... :-X

2) Off-Topic: If you install XP from a CD, make sure you HD is on the SAME controller as your CD-ROM - otherwise standalone XP install WON'T detect the CD! ??? ::) >:(  Took the third install before I figured out this was the problem. :-[  It appeared to install, but some (only some) files wouldn't get built...

Cheerz,

Paolo
« Last Edit: June 22, 2005, 03:22:04 pm by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 6623
  • Karma: +62/-6
    • View Profile
Re: Association or aggregation?
« Reply #4 on: June 22, 2005, 03:35:19 pm »
When reverse engineering, EA will always create an association (in the literal sense as opposed to the aggregation is an association sense) for that sort of attribute if no other association (is the aggregation is an association sense) already exists to represent it.

If EA creates the association, it will set the label.  Otherwise it will leave it, even if it is blank and matched because of the derived name from options.

Simon

PS. I don't consider Paolo's suggestion about forward & reverse engineering mean.  I'd suggest people try reverse engineering to see how EA handles something when anyone is unsure of how to model it for code engineering purposes in EA.
« Last Edit: June 22, 2005, 03:38:03 pm by simonm »
Eve

support@sparxsystems.com

Christopher_Wells

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Association or aggregation?
« Reply #5 on: June 22, 2005, 04:43:52 pm »
Hi Paolo,

Thanks for the instruction.

> But as an experiment (and to provide you with some immediate feedback) create a couple of examples using  different types of Association and Aggregations (in particular use an Association with aggregation set vs Aggregation) and forward engineer.

Alright. I can't guarantee this is interesting though!

The model always *forward-engineers* to the same source code, i.e. "Bar m_bar", no matter whether I model it as:

* Aggregate from Bar to Foo
* Compose from Bar to Foo
* Associate from Foo to Bar

A *reverse-engineer* (of a data member previously undefined in the model) results in the 3rd of these (an "association to the member", not an "aggegation or composition from the member").

A *synchronization* of source with anything already in the model preserves whatever was already in the model.

> I already did the test within he first week I had EA.  I just couldn't remember the outcome.

Perhaps the message I should take away is that the difference doesn't matter much: that I should read/consider "associate to" as more-or-less synonymous with "aggregate/compose from".

Christopher

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 6533
  • Karma: +126/-95
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Association or aggregation?
« Reply #6 on: June 22, 2005, 07:21:21 pm »
Hi Christopher,

You may care to view:
http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.pl?board=UMLPRO;action=display;num=1118175557;start=2#2

EA (for some reason) makes a distinction between an Association with associationKind (Aggregation: feature) set to other than none. :(

UML doesn't make that distinction.

In my opinion, the message you should take from your experiment is that you should adjust the model after reverse engineering to be conceptually correct.  The current code generation process doesn't handle the creation of the destructor body to correctly implement shared versus composite aggregation, but one day, hopefully will.  In any event, the model should be used to communicate the correct information.

For my part, I try to make sure I've got the aggregation right in the model and I ONLY use Associations, setting the Aggregation feature appropriately (on the appropriate end - as required).  A bit more work, but safer.

BTW: As you've seen, reverse engineering sets to Association as does XMI import (from most other tools).

HTH,

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

Christopher_Wells

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Association or aggregation?
« Reply #7 on: June 23, 2005, 06:13:04 am »
Paolo,

> You may care to view

I see there that you had a question there like mine, recently.

> EA (for some reason) makes a distinction between an Association with associationKind (Aggregation: feature) set to other than none.  UML doesn't make that distinction.

Yes: that's the way the situation seemed to me. I found that confusing. I thought I should check it with you, especially since I'm not especially familiar with EA nor with UML.

> The current code generation process doesn't handle the creation of the destructor body to correctly implement shared versus composite aggregation, but one day, hopefully will.

I see. Perhaps for now you can do this by explicitly including the various species of [Boost] auto-pointer in the model, so that there's one-to-one mapping from the model to the [template] classes which implement who destroys what?

In any case I'm using C# so destructors aren't such an issue for me.

> For my part, I try to make sure I've got the aggregation right in the model and I ONLY use Associations, setting the Aggregation feature appropriately (on the appropriate end - as required).  A bit more work, but safer.  As you've seen, reverse engineering sets to Association as does XMI import (from most other tools).

Got it. Thanks for confirming that what I'm seeing is as-expected, and for telling me how you work-around that.

I found it especially confusing that the direction of the connector (not only the type of the connector) changes too: e.g. an aggegation from containee to container, or an association from container to containee.

Thanks again,
Christopher

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 6533
  • Karma: +126/-95
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Association or aggregation?
« Reply #8 on: June 23, 2005, 06:31:56 am »
Quote
Paolo,
[SNIP]

I found it especially confusing that the direction of the connector (not only the type of the connector) changes too: e.g. an aggregation from containee to container, or an association from container to containee.

Thanks again,
Christopher
There's an option called Draw Aggregations Reversed located on the Options - Objects page that governs that.  BUT before you enable it, read the help carefully and then look at:
http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.pl?board=UMLPRO;action=display;num=1117968786;start=0#0
This discussion is part of what led me to adopt the mechanism I now use.

For my part, given that UML 2 formally defines a named association end role as an attribute, my feeling is that most normal aggregations are from source (aggregate) to destination (aggregated).

HTH,

Paolo
« Last Edit: June 23, 2005, 07:00:05 am by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Christopher_Wells

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Association or aggregation?
« Reply #9 on: June 23, 2005, 06:56:18 am »
http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.pl?action=search2 isn'tt accepted by YaBB as a valid URL / search string ...

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 6533
  • Karma: +126/-95
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Association or aggregation?
« Reply #10 on: June 23, 2005, 07:02:51 am »
Quote
http://www.sparxsystems.com.au/cgi-bin/yabb/YaBB.pl?action=search2 isn't accepted by YaBB as a valid URL / search string ...
DOH!!!  
Went searching for Draw Aggregations Reversed and pasted the search URL!!! :-[ :-[
Now fixed...  (and tested! ;D)

Embarrassingly,

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

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 6533
  • Karma: +126/-95
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Association or aggregation?
« Reply #11 on: February 02, 2010, 11:42:25 am »
See: Aggregation and Association proposal for a proposal to provide consistent processing and rendering of EA Aggregations, Compositions and Associations.

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