[Types-sig] Interfaces: Scarecrow implementation v 0.1 is available

John Skaller skaller@maxtal.com.au
Wed, 02 Dec 1998 18:18:19 +1000


[Scarecrow v 0.1]

I'll try to add this to interscript, and integrate it with my protocols
module. :-)
Sigh. It's a special case of a protocol.

>  Special-case handling of classes
>
>    Special handling is required for Python classes to make assertions
>    about the interfaces a class implements, as opposed to the
>    interfaces that the instances of the class implement.  You cannot
>    simply define an '__implements__' attribute for the class because
>    class "attributes" apply to instances.

        Yes you can. And you must. See below.

>    By default, classes are assumed to implement the Interface.Standard.Class
>    interface.  A class may override the default by providing a
>    '__class_implements__' attribute which will be treated as if it were
>    the '__implements__' attribute of the class.

        This cannot work. What you need to do is fix the lookup routines,
that is, the routines that test if an object provides an interface, etc,
so that they look in the dictionary of an object directly!

        Don't use 'getattr', use

        object.__dict__.has_key('__implements__')

and

        object.__class__.__dict__.has_key('__class_implements__')

        This works, it is what I do in my protocols module,
and it gets rid of the special case, which is a sure sign of a design fault.


>  Trial baloon: abstract implementations
>
>    Tim Peter's has expressed the desire to provide abstract
>    implementations in an interface definitions, where, presumably, an
>    abstract implementation uses only features defined by the
>    interface.  For example:
>
>      class ListInterface(Interface.Standard.MutableSequence):
>
>        def append(self, v):
>           "add a value to the end of the object"
>
>	def push(self, v):
>           "add a value to the end of the object"
>           self.append(v)

        Yes. This is useful. It is the basis for mixins in C++.
But one has to ask the question: why not just use a class,
and add a 'defer' keyword to Python.

        Then again, you could just say 'pass'. 

>Issues
>
>  o What should the objects that define attributes look like?
>    They shouldn't *be* the attributes, but should describe the
>    the attributes.

        Obviously, they should themselves be interfaces.
Since attributes are just objects. :-)
-------------------------------------------------------
John Skaller    email: skaller@maxtal.com.au
		http://www.maxtal.com.au/~skaller
		phone: 61-2-96600850
		snail: 10/1 Toxteth Rd, Glebe NSW 2037, Australia