Monday, February 08, 2010

Practical Php Patterns: Structural patterns summary

This post is part of the Practical Php Pattern series.

The GoF book says there is a lot of similarity between structural patterns because of the few kinds of relationships in object model structures: inheritance and implementation between classes plus object composition, which is the leitmotif of the majority of these patterns.
The greatest advantage of object composition consists in being a relationship which can be established at runtime and basing on configuration without changing actual code, an operation that is required by class inheritance and implementation of interfaces. In fact, ideally you can totally define the functionalities of an application by changing the link between objects, and not the ones between classes, which are part of the design. This will be expanded in the next articles on behavioral patterns.
Here is the list of the structural patterns treated in the GoF book and in this article series.

These three patterns' intent is fighting coupling:
  • an Adapter connects objects with different interfaces.
  • a Bridge separates a hierarchy of M abstractions and a hierarchy of N implementations into N+M ortoghonal classes instead of M*N use cases.
  • a Facade creates a new unified interface to access a subsystem.
These three patterns maintain the same interface of an object whilst they add orthogonal concerns without the client noticing, transparently:
  • a Composite implementation adds containers for other objects to organize a hierarchical structure and reuse trees as leafs of other trees.
  • a Decorator adds behavior by intercepting methods delegation, avoiding the introduction of an hign number of subclasses.
  • a Proxy delegates operations to an object that does not exist yet or is hard to access.
Finally, the Flyweight pattern is a standard implementation for ValueObjects with no identity.


Anonymous said...

will these posts be available in a pdf file?
Thank you

Giorgio said...

After the behavioral patterns part is complete and some more posts about non-GoF patterns, I will probably collect all the stuff for an ebook like on the model of Practical Php Testing. :)

marsbomber said...

Thanks very much for this! I've read your Practical PHP Testing PDF, nice and simple to understand! This design patterns series is going to be good too!!!