3 Replies - 2700 Views - Last Post: 17 September 2010 - 07:41 AM

#1 samuraitux  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 65
  • Joined: 29-April 09

Are PHP design patterns overated?

Post icon  Posted 08 September 2010 - 08:31 PM

I recently got the book PHP objects, Patterns, and Practice and read the book from cover to cover. While I found it very fascinating and at times found a new coding method or two, It left me with an impression that Patterns seem to have been a fad more so in the PHP area. What do you guys think? I have seen some really good applications that combine OOP and procedural based coding together. Like collabtive and mantis.

I can see the singleton pattern being used most often but what are some other patterns that you typically find yourself using and what lead you to that decision?

Just trying to get a feel of what other developers are doing.

Is This A Good Question/Topic? 0
  • +

Replies To: Are PHP design patterns overated?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3530
  • View blog
  • Posts: 10,179
  • Joined: 08-June 10

Re: Are PHP design patterns overated?

Posted 08 September 2010 - 10:52 PM

the patterns I use are the Registry Pattern and a mixture of the Registry and Singleton, sometimes also a Factory.
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: Are PHP design patterns overated?

Posted 09 September 2010 - 12:40 PM

Well patterns are not a fad and they are not related just to PHP. A pattern you can use in one language can be applicable to another. They have been around for quite some time actually since they are related to software design in general.

Having said that, some patterns are certainly more useful than others in certain situations. Some of the patterns I use are...

1) Singleton - Mainly for resource intensive objects that I only need one of like establishing database connections.
2) Chain of Responsibility - Great for message processing where you have a ton of handlers or specialized handlers.
3) Factory - Hey, sometimes you need to have an object generator.
4) Decorator Pattern - Essentially wrapper functionality. Take an object, wrap it inside another to disguise it (or add functionality to) an object. Python can use these well.
5) Composite - Group multiple similar objects into one object to then be more easily manipulated or passed around.

Some of the others are really specialized and I hardly ever use them unless in a very specialized situation. But keep in mind that the ultimate goal is readability, maintainability, efficiency and code reuse. If your code already does those things, you don't NEED to have patterns.

:)
Was This Post Helpful? 2
  • +
  • -

#4 nightscream  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 237
  • Joined: 04-December 08

Re: Are PHP design patterns overated?

Posted 17 September 2010 - 07:41 AM

They are definitely not overrated but you don't have to use them if they have no addition to your coding. You don't always need patterns but sometimes they do great work.

In OO (PHP and other OO languages) you also have the iterator pattern (with many variations, it may come in handy)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1