PHP5's Object Oriented features has enabled programmers to use advanced programming techniques like Design patterns.
What are Design Patterns?
From wikipedia, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.
If you have been programming long enough, I am sure you have used one or more of them..
Here are a few Design Patters that are commonly used:
- Factory - Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
- Singleton - Ensure a class only has one instance, and provide a global point of access to it.
- Registry - Provides a mechanism for storing data globally in a well managed fashion, helping to prevent global meltdown.
- Strategy - Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
- Observer - Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
- Specification - Recombinable business logic in a boolean fashion.
When should it be used?
It should only be used if and only if the situation requires it and your . You should not use design pattern in small projects which only requires a simple designs.
Through the years, programmers have been catalogueing them in books. The most notable are Martin Fowler's Patterns of Enterprise Application Architecture and Gang of Four's (Gof) Design Patterns: Elements of Reusable Object-Oriented Software. These books are great references when studying Design Patterns.
Comments
blog comments powered by Disqus