Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91163 > unrolled thread

Re: mix-in classes

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2015-05-24 01:39 -0600
Last post2015-05-24 01:39 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: mix-in classes Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-24 01:39 -0600

#91163 — Re: mix-in classes

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-05-24 01:39 -0600
SubjectRe: mix-in classes
Message-ID<mailman.8.1432453224.5151.python-list@python.org>
On Sat, May 23, 2015 at 7:53 PM, Dr. John Q. Hacker
<zondervanz@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?

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web