Professional Documents
Culture Documents
// No implementation yet
// (return 0 so it will compile)
return 0;
}
}
In the example above, the CoffeeCup class contains a reference to one other obje
ct, an object of type Coffee. Class Coffee is defined is a separate source file.
The relationship modeled by composition is often referred to as the "has-a" rela
tionship. In this case a CoffeeCup has Coffee. As you can see from this example,
the has-a relationship doesn't mean that the containing object must have a cons
tituent object at all times, but that the containing object may have a constitue
nt object at some time. Therefore the CoffeeCup may at some time contain Coffee,
but it need not contain Coffee all the time. (When a CoffeeCup object doesn't c
ontain Coffee, its innerCoffee field is null.) In addition, note that the object
contained can change throughout the course of the containing object's life.
[bv: need to add UML diagram for composition, and explain the difference between
composition and agregation and why I draw my diagrams like I do.]