Book a Demo

Author Topic: members in class diagrams  (Read 8375 times)

Lode

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
members in class diagrams
« on: December 03, 2007, 06:55:19 am »
I use Enterprise Architect for UML class diagrams. In a class diagram, there are many different arrows and I never know what to use for what.

The main ones are:

Associate: just a line
Generalize: a line with a triangle, I use this one for inheritance
Compose: a line with a black diamond
Aggregate: a line with a white diamond

(The other ones are less relevant I think)

I use the "Generalize" arrow for inheritance, and the "Compose" arrow for when something is a member.

Also, for the "Generalize" arrow, I put the triangle at the side of the class I inherit from, while for the "Compose" I put the diamond at the class that has got the member.

But I think it's not necessarily correct what I do with Compose, and explanations of UML are very, very, vague to me about what to do when a class is a member of another. It's as if in their explanations they try to avoid any wording that would make clear which side of the arrow is the member and the class containing the member. I also don't know the difference between compose and aggregate.

So, which arrows to use for the following C++ situations? In the code below, the classes are assumed to have more functions and members that I don't mention (instead of empty classes).

1.) Inheritance: This one is just a simple warmup :)

class A
{
};

class B : public A
{
};




2.) A member

class A
{
};

class B
{
 A a;
};




3.) A pointer to a member --> does it matter here whether or not A "owns" this pointer (e.g. by deleting it in its dtor)?

class A
{
};

class B
{
 A* a;
};




4.) a vector of members

class A
{
};

class B
{
 std::vector<A> a;
};




5.) a vector of pointers

class A
{
};

class B
{
 std::vector<A*> a;
};




6.) Using it as function parameter

class A
{
};

class B
{
 void doSomething(A& a);
};




7.) Inheriting with the class in a template parameter

template<typename T>
class X
{
};

class A
{
};

class B : public X<A>
{
};


How should a class diagram in each of these cases look, according to those arrow types of enterprise architect?

Thanks! :)

jeshaw2

  • EA User
  • **
  • Posts: 701
  • Karma: +0/-0
  • I'm a Singleton, what pattern are you?
    • View Profile
Re: members in class diagrams
« Reply #1 on: December 03, 2007, 10:16:40 am »
Why don't you reverse engineer them in to EA and see what you get?  You can use this technique for the follow-on questions you'll have after these.
« Last Edit: December 03, 2007, 10:17:06 am by jeshaw2 »
Verbal Use Cases aren't worth the paper they are written upon.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: members in class diagrams
« Reply #2 on: December 03, 2007, 10:52:33 am »
And perhaps take a look at one of several good but brief UML books out there. Doing so might not answer all your questions, but it would probably point you in the correct direction to get what you need.

Off hand I'd suggest Elements of UML 2.0 Style by Scott W. Ambler, or UML 2.0 in a Nutshell from O'Reilly. However, there are many others, perhaps more suited to what you need.

In this forum there have been a few threads on the subject of good UML resources, pitched for just about every level of reader. Try searching for one or two of these threads - you'll likely get multiple hits from each since they are quite long - and take the time to read through.

David
No, you can't have it!

Lode

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: members in class diagrams
« Reply #3 on: December 04, 2007, 12:36:09 am »
Ok, I've reverse engineered it with EA, but I must say I'm a little bit disappointed. Is it possible that EA doesn't really know too much about std::vectors and inheritance from template classes?

Here's the result (hosted at imageshack):



The arrows between A2/B2 and A3/B3 appear to be Association arrows. Is that the correct usage for classes with members as well as classes with a pointer to a member?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: members in class diagrams
« Reply #4 on: December 04, 2007, 05:25:59 am »
Quote
...
The arrows between A2/B2 and A3/B3 appear to be Association arrows. Is that the correct usage for classes with members as well as classes with a pointer to a member?

Yes, I think it is. How would you refer to the attribute in code, and what type would you expect it to be? I believe these questions are adequately answered. If you set the appropriate options in Source Code Engineering you should get the expected results regarding pointers versus direct references.

As to the template classes, you should search the forum for this. It has been discussed. You'll find out more about what EA can do for you here, and EA's limits.

David
No, you can't have it!

Lode

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: members in class diagrams
« Reply #5 on: December 04, 2007, 06:46:21 am »
How can I place such an Association arrow manually?

I've looked through the "Tools" of all diagram types, and I didn't find the "Associate" arrow in any of them...

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: members in class diagrams
« Reply #6 on: December 04, 2007, 07:24:03 am »
Create a class diagram (Logical Model). The default toolbox set will include a group of connectors. The first one of these is Associate.
No, you can't have it!

Martin Spamer

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: members in class diagrams
« Reply #7 on: December 11, 2007, 07:38:48 am »
Since UML is implementation language independent defining the code behind the notation is a job for your Software/Technical Architect.  

However you can infer certain things from the constraints of the UML specification.

Firstly Aggregation & Composition are specialisations of Association.  An association is an unrefined relationship therefore I only use them on domain models.  When I produce concrete class models I refine associations into Compositions, Aggregation or associative classes.

A composition is a whole part relationship with a lifetime constraint. e.g. a Car composes of an Engine & Body.

An aggregation is a temporal relationship with no lifetime constraint between the objects.  e.g. the relationships between a car and it's driver/owner.  The driver/owner and the car normally exist seperately from each other.

We therefore can infer the following implementations Idioms for composition and aggregation.


// Composition
Class Car {
 Engine engine;
 Body body;
 Car(Engine engine, Body body) { ... }
}

// Aggregation
Class Car {
 Person driver;
 drive(Person driver} { ... }
}


Made correction re: Paolo F Cantoni comment below.
« Last Edit: January 02, 2008, 06:46:31 am by Martin_Spamer »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: members in class diagrams
« Reply #8 on: December 11, 2007, 01:31:51 pm »
Quote
Firstly Aggregation & Composition are generalisations of Associations.
Hi Martin,

Aren't they Specializations of Association?

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