Sign in to follow this  

Composition and aggregation in UML

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I use Enterprise Architect for UML 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 would a class diagram in each of these cases look, according to those arrow types of enterprise architect? (or other UML programs, I hope they all use the same kind of UML?) Thanks! :)

Share this post


Link to post
Share on other sites

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this