PHP Design Patterns Reference and Examples

PHP, PHP Frameworks, Website Developing

What is GoF in design patterns?

GoF is actually a commonly used acronym that stand for Gang of Four. The Gang of Four refers to the four authors of the popular book on design patterns called “Design Patterns: Elements of Reusable Object-Oriented Software”. This book is considered to be the bible on design patterns in software engineering. Often, GoF is just used to refer to the book itself, and not the actual authors of the book. Another commonly used acronym is Go4, which means the exact same thing. The Gang of Four : Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, authors of the original Design Patterns book.

GoF Creational Patterns
Abstract Factory Sets of methods to make various objects.
Builder Make and return one object various ways.
Factory Method Methods to make and return components of one object various ways.
Prototype Make new objects by cloning the objects which you set as prototypes.
Singleton A class distributes the only instance of itself.
GoF Structural Patterns
Adapter A class extends another class, takes in an object, and makes the taken object behave like the extended class.
Bridge An abstraction and implementation are in different class hierarchies.
Composite Assemble groups of objects with the same signature.
Decorator One class takes in another class, both of which extend the same abstract class, and adds functionality.
Facade One class has a method that performs a complex process calling several other classes.
Flyweight The reusable and variable parts of a class are broken into two classes to save resources.
Proxy One class controls the creation of and access to objects in another class.
GoF Behavorial Patterns
Chain Of Responsibility A method called in one class can move up a hierarchy to find an object that can properly execute the method.
Command An object encapsulates everything needed to execute a method in another object.
Interpreter Define a macro language and syntax, parsing input into objects which perform the correct opertaions.
Iterator One object can traverse the elements of another object.
Mediator An object distributes communication between two or more objects.
Memento One object stores another objects state.
Observer An object notifies other object(s) if it changes.
State An object appears to change its` class when the class it passes calls through to switches itself for a related class.
Strategy An object controls which of a family of methods is called. Each method is in its` own class that extends a common base class.
Template An abstract class defines various methods, and has one non-overridden method which calls the various methods.
Visitor One or more related classes have the same method, which calls a method specific for themselves in another class.
Other PHP Design Patterns
Non OO MVC MVC – Model View Controller – shown using procedural and not OO architecture.
Object Oriented PHP Basics
PHP OO Class Basics The basics of creating a class with OO PHP.
PHP OO Abstract Class Basics The basics of creating an abstract class with OO PHP.
PHP OO Interface Basics The basics of creating an interface with OO PHP.
PHP OO Static Basics The basics of using Statics with OO PHP.
PHP OO This and Parent Basics The basics of using this and parent with OO PHP.
PHP Performance Testing
PHP Performance Tuning if / elseif VS switch Which is faster in PHP – if / elseif or switch?
Other PHP Stuff
PHP Job Interview Questions As a contractor and freelancer I`ve had a number of interviews, and the same questions seem come up on a regular basis.
Comments and Questions A few of the many emails about patterns and PHP I have gotten over the past few years.

Reference: http://www.fluffycat.com/PHP-Design-Patterns/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s