|
Posted by Rik Wasmus on 09/28/07 08:06
On Fri, 28 Sep 2007 10:03:05 +0200, Willem Bogaerts
<w.bogaerts@kratz.maardanzonderditstuk.nl> wrote:
>> I'm trying to learn patterns, which I hope to use in my PHP code,
>> although I'm finding it hard to get any real impression of how patterns
>> fit in properly, I've done the following test code for Decorator pattern
>> and want to know:
>>
>> a) is it correct, this is decorator pattern?
>> b) how would i use this in practice with a database, eg. how would i
>> store the 'attributes' in tables, and how would the 'pattern' be used in
>> conjunction?
>>
>> Any hints, tips, pointers to examples would be appreciated:
> The GOF book ("Design Patterns") is quite clear, I think.
>
> <snipped example>
>
> A decorator is a class that adds functionality at runtime. Functionality
> you could add to your objects in that way are things like spread
> payment, discount conditions, etc. The point of the pattern is that you
> can add responsibility to specific objects instead of whole classes. It
> is an alternative to subclassing (your example was subclassing).
Yup, and Matt Zandstra has a pretty handy real decorator pattern example
in PHP in his book ('PHP 5 Objects, Patterns, and Practice' I believe).
--
Rik Wasmus
[Back to original message]
|