Wednesday, October 27, 2010

Composition

Composition is said to be an has-a relationship; one object is composed of other objects. For instance, a car object is actually composed of many other objects such as an engine, doors, steering wheel etc.

The class diagram below is an example of composition, you will notice that the Player class has two has-a relationships. In plain English we can say that a Player object has a Sword object and a Player object has a Flight object.


You will notice there is a number on each relationship. This number represents the multiplicity between the objects in the relationship. In this example, a Player has one(1) Sword object and one(1) Flight object.

The example above shows the correct notation to illustrate composition in a class diagram.

No comments:

Post a Comment