[Zope3-Users] To Subclass, or to Adapt?

James Allwyn jamesallwyn at yahoo.co.uk
Thu Aug 11 06:36:53 EDT 2005


Thanks for the quick response.

I think I get this - because the real world objects
that my Zope objects are representing really are sub
classes of 'Accommodation', it makes sense to use
sub-classes to represent them. This is the "in any
system" part of your categorisation - they really are
sub-classes, so it would make sense to represent them
as such "in any system".

Now, I think our rating scheme fits more into the
second category:

> if the
> additional feature you try 
> to implement has to do with the object's behavior in
> the system, it should be 
> in an adapter.

This rating scheme will be a specific feature of this
system. Here we might want to calculate a 'marks out
of ten' rating for accommodation, but if the objects
were re-used in another system, that system may want
to look at them and give them a five-star rating, or a
percentage rating (or whatever). Does this make sense?

If so, I guess we will be building an adapter along
similar lines to the size adapter both Stephan and
Phillip use as an example in their books - maybe
create an IRating interface, and create adapters for
each of the sub-classes to adapt those to IRating?

Thanks for the help,

--- Stephan Richter <srichter at cosmos.phy.tufts.edu>

> On Wednesday 10 August 2005 14:01, James Allwyn
> wrote:
> > I would appreciate any guidance on what the
> > recommended Zope3-ish way of handling this would
> be. I
> > feel the options are either to create a generic
> > IProperty object, and subclass it to IHouse,
> > ICateredHall, ISelfCateredHall, IHomeStay, or
> > whatever, which each add extra features or
> > constraints; or to go down some sort of adapter
> route.
> In this particular case I would go with
> sub-classing, though usually I 
> recommend the use of adapters. Basically, if the
> additional feature you try 
> to implement has to do with the object's behavior in
> the system, it should be 
> in an adapter. If the feature is characteristic of
> the object inside any 
> system, it should be directly provided by the
> object.
> > Regarding the Adapters route, in his book Phillip
> > gives an analogy of Interfaces as a contract that
> an
> > object uses to promise its functionality. If an
> > Interface promises that an object will have a
> given
> > method, does it have to provide it directly, or
> can it
> > use an adapter to provide it?
> If an object promises it provides an interface it
> has to do so directly, not 
> via an adapter.
> Regards,
> Stephan
> -- 
> Stephan Richter
> CBU Physics & Chemistry (B.S.) / Tufts Physics
> (Ph.D. student)
> Web2k - Web Software Design, Development and
> Training

To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com

More information about the Zope3-users mailing list