Saturday, April 12, 2008

PHP Design Patterns

Patterns Using PHP

Design patterns are basically a general method that can be used in solving a variety of different problems.

What are Design Patterns

Design Patterns are simply defined solutions to common problems. Design patterns are not created by someone who sits in a room and decides to make a design pattern instead design patterns are proven solutions that are implemented over and over again through different projects. This re-use of the solution itself becomes a pattern. Don't be intimidated by the fancy names given to design patterns, such as façade, singleton or observer, they are exactly that just fancy names given to repeatable solutions.

What Design Patterns Are NOT

  • A design pattern is NOT a template rather a proposed solution that is not implementation specific. In other words you can take the same design pattern and implement it with any language, of course if the design pattern is an OO design pattern you need to implement it with an object-oriented language. More importantly the implementation itself may vary from project to project because of project restraints and requirements.
  • A design pattern is NOT a framework, though depending on whom you speak to, a group of design patterns maybe considered as a design framework.

Why Use Design Patterns

Most PHP developers may first ask why use Design Patterns or why design in the first place. After all PHP is a scripting language usually used for simple web development, aren’t functions are good enough?

Yes this is probably true if you work alone on small projects. But you will find Design and Design Patterns are beneficial in regards of:

  • Maintenance
  • Documentation
  • Readability
  • Easy when developing in large development teams
  • Developing Code to be used by other then yourself

Most enterprise applications that succeed are because of the fact that a good methodology and development process is in place, and apart of that comes design and with design more then likely comes design patterns.

However there is a trade off with design patterns because it adds another layer/component of abstraction there maybe a loss in performance and efficiency. Granted this may not be noticeable on high-end servers, but could be problem on low-end servers.

Some common PHP Patterns

Some other design patterns



    No comments: