Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Learning PHP Design Patterns
Dedication
Preface
Audience
Assumptions This Book Makes
Contents of This Book
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
I. Easing into the Fundamentals of Design Patterns
1. PHP and Object-Oriented Programming
Entering into Intermediate and Advanced Programming
Why Object-Oriented Programming?
Making Problem Solving Easier
Modularization
Classes and Objects
Single Responsibility Principle
Constructor Functions in PHP
The Client as a Requester Class
What About Speed?
The Speed of Development and Change
The Speed of Teams
What’s Wrong with Sequential and Procedural Programming?
Sequential Programming
Procedural Programming
Pay Me Now or Pay Me Later
2. Basic Concepts in OOP
Abstraction
Abstract Classes
Abstract Properties and Methods
Interfaces
Interfaces and Constants
Type Hinting: Almost Data Typing
Encapsulation
Everyday Encapsulation
Protecting Encapsulation through Visibility
Private
Protected
Public
Getters and Setters
Inheritance
Polymorphism
One Name with Many Implementations
Built-In Polymorphism in Design Patterns
Easy Does It
3. Basic Design Pattern Concepts
The MVC Loosens and Refocuses Programming
Basic Principles of Design Patterns
The First Design Pattern Principle
Using Interface Data Types in Code Hinting
Abstract Classes and Their Interfaces
The Second Design Pattern Principle
Basic Composition Using a Client
Delegation: The IS-A and HAS-A Difference
Design Patterns as a Big Cheat Sheet
Organization of Design Patterns
Creational patterns
Structural patterns
Behavioral patterns
Class category
Object category
Choosing a Design Pattern
What Causes Redesign?
What Varies?
What Is the Difference Between Design Patterns and Frameworks?
4. Using UMLs with Design Patterns
Why Unified Modeling Language (UML)?
Class Diagrams
Participant Symbols
Relationship Notations
Acquaintance Relations
Aggregation Relationship
Inheritance and Implementation Relations
Creates Relations
Multiple Relations
Object Diagrams
Interaction Diagrams
The Role of Diagrams and Notations in Object-Oriented Programming
Tools for UMLs
Other UMLs
II. Creational Design Patterns
5. Factory Method Design Pattern
What Is the Factory Method Pattern?
When to Use the Factory Method
A Minimalist Example
Factory Work
The Product
The Client
Accommodating Class Changes
Adding Graphic Elements
Coordinating Products
Changing the Text Product
Changing the Graphic Product
Adding New Products and Parameterized Requests
One Factory and Multiple Products
The New Factories
The New Products
The Client with Parameters
Helper Classes
File Diagram
Product Changes: Leave the Interface Alone!
6. Prototype Design Pattern
What Is the Prototype Design Pattern?
When to Use the Prototype Pattern
The Clone Function
Constructor Does Not Relaunch with Clone
The Constructor Function Should Do No Real Work
A Minimalist Prototype Example
Studying Fruit Flies
The abstract class interface and concrete implementation
The Client
Adding OOP to the Prototype
The Modern Business Organization
Encapsulation in the Interface
The Interface Implementations
The Organizational Client
Making Changes, Adding Features
Dynamic Object Instantiation
Variables to objects
The Prototype in PHP Land
III. Structural Design Patterns
7. The Adapter Pattern
What Is the Adapter Pattern?
When to Use the Adapter Pattern
The Adapter Pattern Using Inheritance
A Minimal Example of a Class Adapter: The Currency Exchange
Enter the euro
Creating a euro adapter
The Adapter Pattern Using Composition
From Desktop to Mobile
Just the desktop
Adapting to mobile
The Client class as participant
Adapters and Change
8. Decorator Design Pattern
What Is the Decorator Pattern?
When to Use the Decorator Pattern
Minimalist Decorator
The Component Interface
The Decorator Interface
Concrete Component
Concrete Decorators
Maintenance
Video
Database
The Client
What About Wrappers?
Primitives in Wrappers
Built-in Wrappers in PHP
Design Pattern Wrappers
Decorators with Multiple Components
Multiple Concrete Components
Concrete Decorators with Multiple States and Values
The Developer Dating Service
Component interface
Concrete components
Decorator with component methods
Concrete decorators
The Client
HTML User Interface (UI)
The Client Class Passing HTML Data
From a Variable Name to an Object Instance
Adding a Decoration
IV. Behavioral Design Patterns
9. The Template Method Pattern
What Is the Template Method Pattern?
When to Use the Template Method
Using the Template Method with Images and Captions: A Minimal Example
The Abstract Class
The Concrete Class
The Client
The Hollywood Principle
Using the Template Method with Other Design Patterns
The Client’s Reduced Workload
The Template Method Participants
The Factory Method Participants
The Hook in the Template Method Design Pattern
Setting Up the Hook
Implementing the Hook
The Client and Tripping the Hook
Setting the Boolean with comparison operators
The Client class
The Small and Mighty Template Method
10. The State Design Pattern
What Is the State Pattern?
When to Use the State Pattern?
The State Machine
Light On, Light Off: The Minimal State Design Pattern
Context Is King
State instances in the Context class
Calling the state methods: Context trigger methods
Setting the current state
The state getters
The Context class summary
The States
OnState
OffState
The Client Request through the Context
Adding States
Changing the Interface
Changing the States
OffState
OnState
BrighterState
BrightestState
Updating the Context Class
An Updated Client
The Navigator: More Choices and Cells
Setting Up a Matrix Statechart
Setting Up the Interface
The Context
The States
Cell1State
Cell2State
Cell3State
Cell4State
Cell5State
Cell6State
Cell7State
Cell8State
Cell9State
The Client Picks a Path
The State Pattern and PHP
V. MySQL and PHP Design Patterns
11. A Universal Class for Connections and a Proxy Pattern for Security
A Simple Interface and Class for MySQL
The Pregnant Interface
Universal MySQL Connection Class and Static Variables
Easy Client
The Protection Proxy for Login
Setting Up Login Registration
Implementing the Login Proxy
The login form and the Client
The Proxy at work
The real subject
The Proxy and Real-World Security
12. The Flexibility of the Strategy Design Pattern
Encapsulating Algorithms
Differentiating the Strategy from the State Design Pattern
No Conditional Statements, Please
A Family of Algorithms
A Minimalist Strategy Pattern
The Client and the Trigger Scripts
The Context Class and Strategy Interface
The Concrete Strategies
DataEntry
DisplayData
SearchData
UpdateData
DeleteRecord
Connection interface and class
Expanded Strategy Pattern with Data Security and Parameterized Algorithms
A Data Security Helper Class
Adding a Parameter to an Algorithm Method
The Survey Table
Data Entry Modules
The Client Calls for Help
The Minor but Major Change in Context Class
The Concrete Strategies
DataEntry
DisplayAll
SearchData
UpdateData
DeleteRecord
The Flexible Strategy Pattern
13. The Chain of Responsibility Design Pattern
Passing the Buck
The Chain of Responsibility in a MySQL Help Desk
Building and Loading the Response Table
InsertData.php
UpdateData.php
The Help Desk Chain of Responsibility
HTML Data Entry, Client and Request Participants
Handler interface and concrete handlers
Automated Chain of Responsibility and Factory Method
The Chain of Responsibility and Date-Driven Requests
Factory Method Finishes Job
The Creator and HungerFactory
The product and individual countries
Helpers, resources, and style
Ease of Update
14. Building a Multidevice CMS with the Observer Pattern
Built-In Observer Interfaces
When to Use the Observer Pattern
Using SPL with the Observer Pattern
SplSubject
SplObserver
SplObjectStorage
The SPL Concrete Subject
The SPL Concrete Observer
The SPL Client
Free Range PHP and the Observer Pattern
The Abstract Subject Class and ConcreteSubject Implementation
Observer and Multiple Concrete Observers
ConcreteObserverDT (Desktop implementation)
ConcreteObserverTablet (Tablet implementation)
ConcreteObserverPhone (Smartphone implementation)
The Client
Making a Simple CMS
CMS Utilities
CMS table
CMS data entry and update
The Multiple Device Observer
Two HTML UI documents
The sniffer client
The Subject classes
Multiple concrete observers
The mobile phone observer
Tablet observer
Desktop view
Thinking OOP
Index
About the Author
Colophon
Copyright
← Prev
Back
Next →
← Prev
Back
Next →