PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 6 ■ OBJECTS AND DESIGN

Figure 6–7. Describing inheritance


The UML describes the relationship between an interface and the classes that implement it as
realization. So if the ShopProduct class were to implement the Chargeable interface, we could add it to
our class diagram as in Figure 6–8.


Figure 6–8. Describing interface implementation


Associations


Inheritance is only one of a number of relationships in an object-oriented system. An association occurs
when a class property is declared to hold a reference to an instance (or instances) of another class.
In Figure 6–9, we model two classes and create an association between them.


Figure 6–9. A class association


At this stage, we are vague about the nature of this relationship. We have only specified that a
Teacher object will have a reference to one or more Pupil objects or vice versa. This relationship may or
may not be reciprocal.
You can use arrows to describe the direction of the association. If the Teacher class has an instance of
the Pupil class but not the other way round, then you should make your association an arrow leading from
the Teacher to the Pupil class. This association, which is called unidirectional, is shown in Figure 6–10.

Free download pdf