PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 9 ■ GENERATING OBJECTS

Figure 9-7. An abstract creator and its abstract products


Implementation


The abstract CommsManager class defines the interface for generating each of the three products
(ApptEncoder, TtdEncoder, and ContactEncoder). You need to implement a concrete creator in order to
actually generate the concrete products for a particular family. I illustrate that for the BloggsCal format
in Figure 9-8.
Here is a code version of CommsManager and BloggsCommsManager:


abstract class CommsManager {
abstract function getHeaderText();
abstract function getApptEncoder();
abstract function getTtdEncoder();
abstract function getContactEncoder();
abstract function getFooterText();
}


class BloggsCommsManager extends CommsManager {
function getHeaderText() {
return "BloggsCal header\n";
}


function getApptEncoder() {
return new BloggsApptEncoder();
}


function getTtdEncoder() {
return new BloggsTtdEncoder();
}


function getContactEncoder() {
return new BloggsContactEncoder();
}

Free download pdf