PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1

CHAPTER 9 ■ GENERATING OBJECTS


The Problem


Let’s look again at the organizer example. I manage encoding in two formats, BloggsCal and MegaCal. I
can grow this structure horizontally by adding more encoding formats, but how can I grow vertically,
adding encoders for different types of PIM object? In fact, I have been working toward this pattern
already.
In Figure 9-6, you can see the parallel families with which I will want to work. These are
appointments (Appt), things to do (Ttd), and contacts (Contact).
The BloggsCal classes are unrelated to one another by inheritance (although they could implement
a common interface), but they are functionally parallel. If the system is currently working with
BloggsTtdEncoder, it should also be working with BloggsContactEncoder.
To see how I enforce this, you can begin with the interface as I did with the Factory Method pattern
(see Figure 9-7).


Figure 9-6. Three product families

Free download pdf