23.07.2012 Views

Design Patterns Explained

Design Patterns Explained

Design Patterns Explained

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2 • The UML— The Unified Modeling Language 35<br />

In this diagram, I also show that an Aircraft is either a Jet or a<br />

Helicopter. I can see that Aircraft is an abstract class because its<br />

name is shown in italics. That means that an Airport will have<br />

either Jet or Helicopter but will treat them the same (as Aircraft). Aggregatio<br />

The open (unfilled) diamond on the right of the Airport class<br />

indicates the aggregation relationship.<br />

The other type of has-a relationship is where the containment<br />

means the contained object is a part of the containing object. This type<br />

of relationship is also called composition.<br />

n<br />

Figure 2-4 The Class Diagram showing composition and the uses<br />

relationship.<br />

Figure 2-4 shows that a Car has Tires as parts (that is, the Car is<br />

made up of Tires and other things). This type of has-a relationship,<br />

called composition, is depicted by the filled in diamond. This dia -<br />

gram also shows that a Car uses a GasStation. The uses relationship<br />

is depicted by a dashed line with an arrow. This is also called a<br />

dependency relationship.<br />

Both composition and aggregation involve one obje ct containing<br />

one or more objects. Composition, however, implies the contained<br />

object is a part of the containing object, whereas aggregation<br />

means the contained objects are more like a collection of things.<br />

We can consider composition to be an unshared association, with<br />

Composition and<br />

uses<br />

Composition versus<br />

aggregation

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!