首页/Home PHP Advanced Programming When To Use Design Patterns And Why

When To Use Design Patterns And Why

PrintE-mail
Sunday, 03 February 2008 17:00  

The article generally talks about what is design pattern, when to use them and, why to use them.
You could hear what are others' opinions...

What Are Design Patterns

Design patterns are a template for how to organize your code so you can take advantage of a tried-and-true design. They are not created by someone who sits in an office and decides to make a design pattern. Instead, design patterns are proven solutions that are implemented over and over again through different projects. It is the re-use of the solution itself becomes a pattern.

What's more, according to an article at mit.edu:

A design pattern is:

  • a standard solution to a common programming problem
  • a high-level programming idiom (design patterns are generalized)
  • a useful design vocabulary buzzword

Why Should We Use Design Patterns

Many PHP programmers may first ask why use Design Patterns. Since PHP is a scripting language usually used for simple web development, aren’t functions good enough?

Well, this is probably true if you work alone on small projects. But chances are that you are working under a team and, you will find Design Patterns are beneficial in regards of:

  • Common Collaboration Among Objects
  • Speed Up Development
  • Less Chance to Crash
  • More Efficient Communication Between Designers
  • Code Reusablity (To be used by other than yourself)
  • Better Readability
  • Easier Documentation
  • Easier Mantenance

How To Use Design Patterns

Learning about patterns is also learning about Object Orientation, since patterns are OO applied to certain types of problems. Here I don't want to be a reteller. Erich Gamma, co-author of the landmark book, Design Patterns, told you the right way to think about and use design patterns.

Here is the link: http://www.artima.com/lejava/articles/gammadp.html

Five Common Design Patterns

It may not be agreed by everybody. According to an article at ibm.com

  • Factory
  • Singleton
  • Observer
  • Command Chain
  • Strategy

Book Recommandation

Head First Design Patterns

 

回复

留个脚印儿吧.


回复