Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How relevant are OO design patterns to web development in PHP?

Singleton, Decorator, Abstract, Factory, and the list goes on. How relevant are OO design patterns in developing PHP applications for the web? Does it do anything for performance? Or is it just to keep code lean for agile development practices? Who is the major benefactor for implementing these design patterns? Is it the customer or the developer?

I realize I am asking multiple questions, but they all relate to the same topic. I am not certain there is a necessity for OO design patterns with a scripting language since it is compiled at run time. What do you all think? Is it important?

like image 249
Chuck Burgess Avatar asked Mar 10 '10 03:03

Chuck Burgess


1 Answers

Design patterns are created to solve specific problems. These problems occur whether you use PHP or any other language (though the patterns may differ by language as well). Most of the patterns have their roots in object-oriented design, but can be adapted to procedural settings. Use the design pattern when you have a problem that the pattern addresses, whether PHP or any other language. Don't use a design pattern just because it's a "design pattern" -- know how and when it applies and when it doesn't.

Having said that, much of what design patterns do, is organize code to accomplish their purpose in a clean, understandable way. There are other ways to solve the problem, but the design pattern is a well-recognized, clear, and understandable method. If you do need to solve a problem addressed by a particular pattern, you would usually be best off using the pattern (or adapting the pattern) rather than choosing an alternative.

Using patterns, where appropriate, is thus beneficial to both current and future developers -- cleaner, better understood code -- and the customer -- less time reinventing the wheel, more robust, maintainable code. Using patterns when they aren't appropriate benefits no one; it's potentially an exercise in frustration trying to adapt a pattern to solve an unrelated problem and more than likely will simply make things more complicated.

like image 177
tvanfosson Avatar answered Oct 26 '22 13:10

tvanfosson