Jump to content
  • Advertisement
Sign in to follow this  
chadsxe

Can someone explain the Composition model in UML

This topic is 4181 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

Advertisement
Composition (line with solid diamond at the composite class end) is used when class A "has a" class B, and the lifetime of an instance of class B is tied to its owning instance of class A.

e.g.

class Element
{
// ...
}

// Composite has a composition relationship with Element
class Composite
{
Element foo; // Created and destroyed with the instance of Composite
}





Aggregation (line with hollow diamond at the aggregate class end) is a form of composition where the lifetime of an instance of class B is not tied to its owning instance of class A.

class Element
{
// ...
}

class Aggregate
{
Element* bar; // Not created or destroyed with the instance of Aggregate
}





A real life (well, sort of) example of composition and of aggregation:

struct Point
{
int x, y;
}

struct TreeNode
{
TreeNode* left, right;
}





This is perhaps a little simplified, but I hope it conveys the idea.

EDIT: Here's the UML itself for the above structures.

UML diagram demonstrating composition and aggregation

EDIT2: That should be "+coordinates", oops.

[Edited by - TheUnbeliever on April 8, 2007 12:51:49 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!