Page 8      All Pages  All Books
10 Table of Contents
The Solution ......................................................... 53
Sample Code ........................................................ 54
Adding a Little Color ................................................. 57
Factories to Hide Object State Setup ................................... 61
Factories to Promote Polymorphism ................................... 63
Factories for Lazy Loading ............................................ 71
Issues ............................................................... 72
4 The Singleton Pattern ........................ 75
The Problem ........................................................ 75
The Solution ......................................................... 76
Sample Code ........................................................ 77
A “Global” Approach ................................................. 77
A Static Approach .................................................... 79
The Singleton in PHP5 ................................................ 80
Issues ............................................................... 81
The Monostate Pattern: Stealth Singletons .............................. 81
5 The Registry Pattern ......................... 85
The Problem ........................................................ 85
The Solution ......................................................... 85
Sample Code ........................................................ 86
An Example ......................................................... 90
Implementing the Registry as a MonoState Object ....................... 92
Implementing with Class Static Variables ............................... 95
Issues ............................................................... 98
Embedded Registry .................................................. 98
6 The MockObject Pattern ..................... 101
The Problem ....................................................... 101
The Solution ....................................................... 102
Sample Code ....................................................... 102
A Legacy Application ................................................ 106
Issues .............................................................. 119
Resources .......................................................... 120

Page 8      All Pages  All Books