PHP Objects, Patterns and Practice (3rd edition)
CHAPTER 8 ■ SOME PATTERN PRINCIPLES Loosening Your Coupling To handle database code flexibly, you should decouple the applicatio ...
CHAPTER 8 ■ SOME PATTERN PRINCIPLES return new TextNotifier(); } } abstract function inform( $message ); } class MailNotifier ex ...
CHAPTER 8 ■ SOME PATTERN PRINCIPLES $mgr->register( $lessons1 ); $mgr->register( $lessons2 ); and the output from a typica ...
CHAPTER 8 ■ SOME PATTERN PRINCIPLES function __construct( $duration, FixedPriceStrategy $strategy ) { $this->duration = $dura ...
CHAPTER 8 ■ SOME PATTERN PRINCIPLES Patternitis One problem for which there is no pattern is the unnecessary or inappropriate us ...
CHAPTER 8 ■ SOME PATTERN PRINCIPLES Enterprise Patterns I look at some patterns that describe typical Internet programming probl ...
C H A P T E R 9 ■ ■ ■ Generating Objects Creating objects is a messy business. So many object-oriented designs deal with nice, c ...
CHAPTER 9 ■ GENERATING OBJECTS class NastyBoss { private $employees = array(); function addEmployee( $employeeName ) { $this-> ...
CHAPTER 9 ■ GENERATING OBJECTS If the NastyBoss class does not instantiate a Minion object, where does it come from? Authors oft ...
CHAPTER 9 ■ GENERATING OBJECTS $class = self::$types[$num]; return new $class( $name ); } function __construct( $name ) { $this- ...
CHAPTER 9 ■ GENERATING OBJECTS // instantiate a BookProduct objec } else if ( $row['type'] == "cd" ) { $product = new CdProduct( ...
CHAPTER 9 ■ GENERATING OBJECTS to installation. The object may also be used as a notice board, a central location for messages t ...
CHAPTER 9 ■ GENERATING OBJECTS return self::$instance; } public function setProperty( $key, $val ) { $this->props[$key] = $va ...
CHAPTER 9 ■ GENERATING OBJECTS Figure 9-2. An example of the Singleton pattern Consequences So, how does the Singleton approach ...
CHAPTER 9 ■ GENERATING OBJECTS The Problem Imagine a personal organizer project. Among others, you manage Appointment objects. Y ...
CHAPTER 9 ■ GENERATING OBJECTS const MEGA = 2; private $mode = 1; function __construct( $mode ) { $this->mode = $mode; } func ...
CHAPTER 9 ■ GENERATING OBJECTS } } } As you can see, the need to support header output has forced me to duplicate the protocol c ...
CHAPTER 9 ■ GENERATING OBJECTS abstract function encode(); } class BloggsApptEncoder extends ApptEncoder { function encode() { r ...
CHAPTER 9 ■ GENERATING OBJECTS Figure 9-5. Extending the design to support a new protocol Consequences Notice that the creator c ...
CHAPTER 9 ■ GENERATING OBJECTS The Problem Let’s look again at the organizer example. I manage encoding in two formats, BloggsCa ...
«
4
5
6
7
8
9
10
11
12
13
»
Free download pdf