mix-in classes

Ian Kelly ian.g.kelly at gmail.com
Sun May 24 03:39:41 EDT 2015


On Sat, May 23, 2015 at 7:53 PM, Dr. John Q. Hacker
<zondervanz at gmail.com> wrote:
> The post on "different types of inheritence..." brought up a thought.
>
> Let's say, I'm adding flexibility to a module by letting users change class
> behaviors by adding different mix-in classes.
>
> What should happen when there's a name collision on method names between
> mix-ins?  Since they're mix-ins, it's not presumed that there is any parent
> class to decide.  The proper thing would seem to call each method in the
> order that they are written within the parent class definition.
>
> I suppose one can create a method in the parent class, that runs the mixin
> methods in the same order as in the inheritance list, but would there be a
> better way for Python to enforce such a practice so as not to create class
> anarchy?  (A problem for another topic.)

Usually with mixins, one just wants to call a method of a specific
mixin; a name collision is likely a symptom of poor design, and it
would be unusual to want to call *all* mixin methods with the same
name. If you really want to do that for a particular method though, is
there some reason why super() won't suffice?



More information about the Python-list mailing list