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

Similar things

  • Learning lessons from Lisp or patterns and languages in PHP
  • Emulating closures in PHP
  • Some ways to use saved state with closures in php
  • Scoped php functions or more ways to abuse php
  • Relations and their domain structures
  • I'm resigned to end my vaporware
  • Learning to speak - erlang style concurrency in haskell
  • Learning to speak - erlang style concurrency in haskell ( part II )
  • Hair@Gate Theatre:
  • Travelling back from Naples

guild
Home » blogs » vlado's blog

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.

vlado's blog | add new comment
Home » blogs » vlado's blog

dikini.net

spreading confusion by accident since 1970