[Zope3-dev] adaptation based on class rather than interface

Chris Withers chris at simplistix.co.uk
Thu Nov 9 06:22:30 EST 2006


Lennart Regebro wrote:
> On 11/9/06, Chris Withers <chris at simplistix.co.uk> wrote:
>> I'm expecting people to say "NO!" very loudly, but I'm interested in the
>> real reasons for why this is bad.
> 
> Well.... it removes the possibility of switching out the class, which
> begs the question why you would have an adapter in the first place. If
> you have a strict one to one relationship between the class and the
> adapter, why not just implemetent the desired functionality directly
> in the class?

It's not one to one:

<adapter
     for=".myclasses.MyClassA"
     provides=".interfaces.ISomething"
     factory=".adapters.MyAdapter1"
     />

<adapter
     for=".myclasses.MyClassB"
     provides=".interfaces.ISomething"
     factory=".adapters.MyAdapter1"
     />

<adapter
     for=".myclasses.MyClassC"
     provides=".interfaces.ISomething"
     factory=".adapters.MyAdapter2"
     />

<adapter
     for=".myclasses.MyClassD"
     provides=".interfaces.ISomething"
     factory=".adapters.MyAdapter2"
     />

Re-use of adapters without having to create or use a mixin...

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk


More information about the Zope3-dev mailing list