On 4/8/02 2:10 AM, "Edmund Lian" <[EMAIL PROTECTED]> wrote:

> I've been trying to work around a multiple inheritance issue (the diamond
> problem that Python 2.2 solves) with Cheetah, and thought of using
> delegation instead of inheritance.
> 
> My first attempt failed because line 183 of ServletFactory is:
> 
>   assert issubclass(theClass, Servlet)
> 
> After commenting out the assertion, I find that delegation works! Now, if
> only Python had some nice syntactic sugar for auto-delegation....
> 
> Anyway, I'd like to argue for the removal of the assertion in
> ServletFactory, since it is denying use of a very powerful, and arguably
> better technique than inheritance. In any case, assertions can be optimized
> away in .pyo files, so that the presence of the assertion statement is of
> questionable value...

I agree (see recent messages by me).  The 'assert' statement should be used
for development/debugging only.

Zope 3 is going away from inheritance hell to delegation hell ;), and
they're using an Interface package primarily written by Jim Fulton as a
scarecrow for how Interfaces might work in Python.  His work was then taken
by Michel Pelletier and submitted as PEP 245 as an actual change to the
language (introducing the 'interface' and 'implements' keyword).

Anyways, I've found myself wishing that their Interface package was
available separately, as it could help Webware a couple of ways:

 1. Documentation - it would help to see what core set(s) of
    methods make up servlet use, and which methods are particular
    to special servlet implementations.

 2. Assertion - Instead of checking 'issubclass()', you could
    instead do 'if not IServlet.isImplementedBy(obj): ...' or
    'IServlet.isImplementedByInstancesOf(klass)', and allow
    developers to programmatically declare support of the
    Servlet interface (most of which they might inherit from
    a superclass).  But support of an interface is separate
    from inheritance, allowing a developer to use an entirely
    different inheritance tree.

Another option would be to introduce a package/kit that allowed writing of
Eiffel style pre/post conditions.  Something this kit could do is offer a
"Prefer(expression)" class that is more of a warning (and maybe used the
warnings framework, or the notional LoggingKit).

ConditionKit.Prefer(issubclass(theClass, Servlet))

This way, you could log 'Prefer' warnings for when the expression isn't
satisfied, or choose to suppress them.

-- 
Jeffrey P Shell 
www.cuemedia.com



_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to