mixins that don't down-call?

Joshua Spoerri jspoerri+keyword+python.8e28f8+keyword+b582c4.6549c2 at earthlink.net
Wed Aug 10 09:51:02 EDT 2005


Anybody have an idea for how to do python mixins that don't down-call?

Thanks

(
Mixins from different vendors might use the same method names for unrelated
features, but should continue to work sensibly.

It's fine to have one mixin method override another in its "public" interface,
but overriding a mixin's internal methods in its "protected" interface should
only happen under explicit extension.

e.g.
def simplyMixin(*classes):
  c = copy.copy(classes[0])
  c.__bases__ += classes[1:]
  return c()

class artist:
 def draw(self): ...
class cowboy:
 def draw(self): ...
 def drawAndShoot(): self.draw() ...
artisticCowboy = simplyMixin(artist, cowboy)()
artisticCowboy.draw() #draw a picture
artisticCowboy.drawAndShoot() #take out gun and fire it
)



More information about the Python-list mailing list