On Tue, 2004-01-13 at 10:43, David Bolen wrote:
> "Ian Sparks" <Ian...@et...> writes:
> > I really meant that Interfaces mean its no longer enough to create a
> > class. I now need to create an Interface "prototype" and then
> > classes that implement that Interface. One of the great things about
> > Python (for me) is that you can say "Does it quack? Ok, lets assume
> > its a duck" without a lot of rigmarole. I'm probably showing my
> > (deep) ignorance but the whole Interfaces thing seems to be putting
> > the rigmarole back in.
>
> What I find attractive about PyProtocols (and probably the others) is
> that you still get the "Does it quack?" approach, but you do so with a
> single adaptation call ("adapt" with PyProtocols"). And that's an
> often discussed topic in the Python arena - just how do you ask "Does
> it quack?"
Interfaces answer "Does it quack" -- adaptation goes a bit further,
saying "Give me something that quacks". Interfaces are like the old,
boring type declarations. They might save you from a few bugs, but they
don't really give you anything. Adaptation adds real power. It
formalizes something we've all been doing in various ad hoc manners for
a long time. It's also an alternative to many kinds of traversal --
though where to draw that line (between doing traversal via attribute
access vs. adaptation) I haven't yet figured out.
> So you don't have to attempt random calls into the object. When you
> couple that with the fact that you can externally adapt or register
> that an object supports an interface, and it's really a very dynamic
> way to handle well-defined interfaces.
>
> The typing really isn't that much. Yes, you need to define an
> interface, but to be honest, you should be doing that anyway as a way
> of documenting the "duck" that your object expects.
And if you are just writing an "application" (vs. a framework), you
probably won't define any interfaces at all. Certainly to use
FormEncode you don't need to define any interface -- it only uses
interfaces that are already defined (IValidator and IField). In fact,
all the adaptation and interfaces are mostly hidden from you. It's
really there for when you want to fit different frameworks together,
like SQLObject and FormEncode.
Ian
|