PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 6 ■ OBJECTS AND DESIGN

Figure 6–14. Aggrgation


Pupils make up a class, but the same Pupil object can be referred to by different SchoolClass
instances at the same time. If I were to dissolve a school class, I would not necessarily delete the pupil,
who may attend other classes.
Composition represents an even stronger relationship than this. In composition, the contained
object can be referenced by its container only. It should be deleted when the container is deleted.
Composition relationships are depicted in the same way as aggregation relationships, except that the
diamond should be filled. We illustrate a composition relationship in Figure 6–15.


Figure 6–15. Composition


A Person class maintains a reference to a SocialSecurityData object. The contained instance can
belong only to the containing Person object.


Describing Use


The use relationship is described as a dependency in the UML. It is the most transient of the
relationships discussed in this section, because it does not describe a permanent link between classes.
A used class may be passed as an argument or acquired as a result of a method call.
The Report class in Figure 6–16 uses a ShopProductWriter object. The use relationship is shown by
the broken line and open arrow that connects the two. It does not, however, maintain this reference as a
property in the same way that a ShopProductWriter object maintains an array of ShopProduct objects.

Free download pdf