Book a Demo

Author Topic: Assocition instead of Aggregation  (Read 5104 times)

juhel

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1 Gold!
    • View Profile
Assocition instead of Aggregation
« on: November 01, 2004, 09:34:11 am »
Hello,

With EA 4.00.729, I create 2 class : Class1 and Class2 and Class2 has a member of type Class1.

When I forward generate the code (in Java) I get :

public class Class2 {

     private Class1 att1;}

Now, when I reverse engineer my 2 classes, EA draws an arrow named 'att1' from Class2 to Class1.

When I right click on this link, I can see that it's an association.

My question is : Why isn't it an aggregation (with a diamond) or a composition?

Regards,

Philippe

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Assocition instead of Aggregation
« Reply #1 on: November 01, 2004, 02:00:58 pm »
Phillipe,

Consider this.  Create two classes, classA and int. Add an attribute to classA and set its type to int.  Round trip it.  Would you then expect to get an aggregation or composition?

Consider also this.  IMO (and very little experience with java) aggregations and compositions have little use at the physical design level.

hth
Bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

Javier

  • EA User
  • **
  • Posts: 67
  • Karma: +0/-0
  • Necessity is the mother of email
    • View Profile
Re: Assocition instead of Aggregation
« Reply #2 on: November 03, 2004, 11:27:41 pm »
Phillipe,

You can consider an aggregation a "kind of" association that has semantics for the roles a class A and class B play.  When you forward-engineer the code, these semantics are unambigious and EA is capable of generating the code the way you need it.

However, when you reverse-engineer the code, I gather EA cannot tell whether it would be a aggregation (hollow diamond) or composition (filled diamond) and it punts for a more generic association.  Without going into details, I imagine that the reverse engineering process can be tailored to what you need--possibly it has defaults--or you have to intervene and modify the association by hand.

Bruce,

I disagree with your statement :

Quote
IMO [snip] aggregations and compositions have little use at the physical design level.


Although it is true that during initial design it is important just to determine the association--regardless of whether it's aggregation or not, hollow/filled diamond, navigability, etc., I believe it is important to qualify the association correctly.  In our environment we make sure that aggregation is expressed correctly: filled diamonds depict the same lifetime for the container and contained object, while hollow diamonds reflect separate lifetimes.

I compare this to use case design, where you start up by identifying the actors associated with a given use case, and you don't care about who starts the use case initially, but after you're done with identifying the actors, then you start filling up the arrows to convey the initiating and receiving actors.

Regards,

Javier
« Last Edit: November 03, 2004, 11:31:18 pm by Javier »
We must become the change we want to see.
- Ghandi

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Assocition instead of Aggregation
« Reply #3 on: November 04, 2004, 02:04:56 pm »
You are right - my statement as it stands was out of hand and incorrect.
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

TrtnJohn

  • EA User
  • **
  • Posts: 176
  • Karma: +0/-0
    • View Profile
Re: Assocition instead of Aggregation
« Reply #4 on: November 08, 2004, 05:32:30 pm »
Quote
 In our environment we make sure that aggregation is expressed correctly: filled diamonds depict the same lifetime for the container and contained object, while hollow diamonds reflect separate lifetimes.
Regards,

Javier


Javier,

I always get confused by this also.  I like the way that you use them though.  But, does this mean that you never user generic associations for classes?  I've always thought of the 2 aggregations as either "Has a" or "Must have a" relationships.  I am not sure what you mean by "Kind of" association.    Can you give more details?

Thanks!

Javier

  • EA User
  • **
  • Posts: 67
  • Karma: +0/-0
  • Necessity is the mother of email
    • View Profile
Re: Assocition instead of Aggregation
« Reply #5 on: November 08, 2004, 11:53:10 pm »
TrTnJohn,

In the most generic terms, all associations can be represented with a dashed arrow and a stereotype.  Bidirectional associations with two dashed arrows, one on each direction

for example, generalization can be a dashed arrow and a <<specialize>> stereotype, composition can be a dashed arrow and a <<has a>> stereotype, etc.

Several of the associations are so common that they deserve their own icon, aggregation (hollow diamond) being one of them, and composition (filled diamond) being another.  Thus my comment on the "kind of" association.  You can think of composition as a kind of aggregation (explanation below).

Now, regarding your comments on aggregation and composition, it is important to note that aggregation (your "has a") has a lifetime implication.  An aggregated instance may have a different lifetime than the aggregating instance.

Composition, on the other hand (your "must have a") , implies that the aggregated and aggregating instances have the same lifetime.  Whan A goes away, B goes away.

Notice that the UML does not say whether A and B are associated during construction of the aggregating class or whether the association is built by calling a method in A after A is constructed.  This is in line with UML, since it takes care of the "logical" design aspect.  In C++ there is another aspect that it's called physical design (by John Lakos).

Lastly, I use generic associations in my designs.  For example, if I want to have a developer notice that A uses B in some way, just draw a dashed arrow pointing to B to note that A depends in some way on B (i.e., uses it in the class "interface", denoting that interface here means all the methods for A and B is used as a parameter in one of the methods).

Regards,

Javier


We must become the change we want to see.
- Ghandi

TrtnJohn

  • EA User
  • **
  • Posts: 176
  • Karma: +0/-0
    • View Profile
Re: Assocition instead of Aggregation
« Reply #6 on: November 09, 2004, 12:28:08 pm »
I see what you mean now.  Your "kind of" meant it was like a stereotype of the generic association.  I agree with your description on lifetimes.  Thinking of the classes that way makes it easier to tell what type of association to use.

Thanks for the clear explanation!