[Dev] SSLDAV class, code design question

John Anderson john at osafoundation.org
Sat Oct 30 14:09:57 PDT 2004


I think you're close: just use standard multiple inheritance. Implement 
all the DAV functionality in a class called DAVMixin:

DAVMixin (object):

now implement

DAV (DAVMixin, httplib.HTTPConnection):

and

SSLDAV (DAVMixin, M2Crypto.httplibs.HTTPSConnection)

Using application.Application.mixinAClass is better left for runtime 
situations and seem unnecessary in this case. If you use new style 
classes (i.e. inherit from object) the diamond case won't call a base 
init more than once. However, that situation doesn't come up in the 
proposal above. Also, I don't know if httplib uses new style classes.

John

Heikki Toivonen wrote:

> Currently the DAV class inherits from httplib.HTTPConnection. There is 
> also M2Crypto.https.HTTPSConnection that inherits from 
> httplib.HTTPConnection. In other words:
>
> httplib.HTTPConnection
>   __init__()
>
> DAV(httplib.HTTPConnection)
>
> M2Crypto.httplibs.HTTPSConnection
>   __init__()
>     httplib.HTTPConnection.__init__()
>
> Now, clearly it would be possible to create SSLDAV class that 
> inherited from M2Crypto.https.HTTPSConnection and duplicated all the 
> code from DAV.
>
> But what is the best way to achieve this without code duplication? At 
> the moment I am thinking that I should make the DAV class not inherit 
> from anything, but make it a mixin class. Then, depending on whether 
> or not we need SSL or non-SSL DAV, we instantiate 
> M2Crypto.httplibs.HTTPSConnection or httplib.HTTPConnection and mix in 
> the DAV class (using application.Application.mixinAClass or something 
> like it.
>
> Other thoughts that have occurred involve diamond inheritance and 
> calling the wrong __init__ or needing to call __init__ more than once 
> which may not be safe.
>
>------------------------------------------------------------------------
>
>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
>Open Source Applications Foundation "Dev" mailing list
>http://lists.osafoundation.org/mailman/listinfo/dev
>  
>


More information about the Dev mailing list