[Tutor] Mixing in and Mixing out classes in python

Alan Gauld alan.gauld at btinternet.com
Fri Aug 1 00:16:40 CEST 2008


"Tomaz Bevec" <tomazbevec at yahoo.com> wrote

> I am using the following function to mixin in classes
> into specific object instances ...

> Is there an analogous way to "Mixout" classes from an instance at 
> runtime?

I'm sure it is possible but...

Are you just asking out of interest?
Or do you have a real world need for this?

Using multiple inheritence is a non trivial aspect of OOP (albeit 
powerful)
that is fraught with difficulty and potential side effects. Adding a 
mixin at
run time is difficult enough, removing one would bend my brain way too
far I suspect. (Many coding standards insist on limiting MI to two 
classes
or even banning it outright as being too bug prone.)

Dynamic mixins add a whole new complexity (it's somewhat akin to
the FAQ here about dynamically naming variables) all you generic
code has to take account of the new method introduced and any
potential side-effects that may not be handled in your code. Unless
your mixin classes are ultra clean and stateless in their 
implementation
you run a risk of breaking things in ways that are almost impossible
to debug.

I've never come across a need for dynamic mixin additions and
I'm interested in how you think you might use this. (CLOS is the only
other place I've even seen this discussed and it's possible there
with some under the covers work but I've never seen it used!)

Curious,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list