[Zope3-dev] Chapter 1 Step 6 now available

Tres Seaver tseaver@zope.com
Tue, 19 Feb 2002 10:16:14 -0500 (EST)


On Mon, 18 Feb 2002, Steve Alexander wrote:

> Tres Seaver wrote:
>  >
> > My problem with Decorator is that it is the name of a recognized
> > GoF design pattern;  the Decorator pattern is somewhat like
> > adapter, in that the decorating object wraps the decorated,
> > but distinct in that the "depended on" and "provided" interfaces
> > are the same.
> >
> > Maybe I misread Steve's description, and the GoF pattern actually
> > fits.
>
> Can you explain why you think my use doesn't fit?
>
> I think it fits.
>
> Take for example
>
>    Decorator.decorate(contactinfo, postalinfo)
>
> ...where contactinfo is an object implementing IContactInfo and
> postalinfo is an object implementing IPostalInfo.
>
> Let's call the resultant object decoratedobject.
>
> If you ask for the interfaces that decoratedobject implements, it will
> return exactly the same as contactinfo would.
>
> If you ask for any other attribute of decoratedobject, it will return
> exactly the same as contactinfo would, except where you ask for a method
> of IPostalInfo, where the method of postalinfo will be returned.
>
> Thus, decoratedobject is just like contactinfo, but with methods of
> IPostalInfo bolted on.
>
> Sounds like the Decorator pattern from "Design Patterns: elements of
> reusable object-oriented software" to me.

It is *almost* Decorator;  the key distinction is that the additional
behavior of the Decorator is an extension / modification of one or
more methods of the interface being "decorated":  the canonical example
is to extend the 'draw' method of a window by adding a border.

In fact, the aquisition-based composition of behaviors here is perhaps
closer to the Gof Chain-of-Responsibility pattern in its guts, where
the chained method is '__getattr__'.

Perhaps we need to write up a GoF-style pattern, 'Acquisition', and
just refer to that. :)

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com