Topics

programming

php drupal scheme scheming macros design patterns da la

design

design css

random thoughts

scribbles

alter ego

other me 'em that link us my space me linked in

Collections

Programmable web
PHP design patterns

Overcomplicated design pattern implementations

Submitted by vlado on Mon, 2006-07-24 17:09.code | php | rants | scribbles

I know that I often express myself in an overcomplicated way. I hope I don't do that in code. I'm really amased how people overcomplicate stuff in their minds. This particular rant is triggered by me wandering around the net flicking design patterns in php web pages.

Guess what? They are complex beasties. With multiple hierarchies of classes doing loads of complicated stuff over a lot of lines of code.

Take a look for example at Observer Pattern. Actually not a very bad code. Still on the big side. Still maintaining the dual observer/observed 'magic' separation. Compare it with this hooks implementation, the code at the bottom of the page. The latter is designed for a more complex scenario, i.e to mimic aspects in php, but still manages to be simpler.

But the best example, I suppose, is how do you code a strategy pattern in php? A typical code would be something like Strategy Pattern. Not a bad code. Well described, documented, etc... But wait! A startegy is:

The Strategy pattern defines an object that represents an algorithm for a particular task.

But algorithm == function (or method), isn't it? So the variable function problems is $func = "a_function"; ... $func()

I think this should do it. Yep, for complex strategies you might need to compose stuff, but still there are surely better ways, rather than having these long hard java/c++/... inherited ideas.

Please, don't be angry woith me, but I'm trying to be polite here.

read more | vlado's blog | add new comment

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <br /> <br> <div> <a> <em> <strong> <cite> <pre> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <img> <blockquote> <q> <strike> <small> <h4> <h5> <h6>
  • Link to content with [[some text]], where "some text" is the title of existing content or the title of a new piece of content to create. You can also link text to a different title by using [[link to this title|show this text]]. Link to outside URLs with [[http://www.example.com|some text]], or even [[http://www.example.com]].
  • Lines and paragraphs break automatically.
More information about formatting options
Home ยป Overcomplicated design pattern implementations

dikini.net

spreading confusion by accident since 1970