Skip to content

Instantly share code, notes, and snippets.

@Alan-FGR
Last active June 17, 2016 03:17
Show Gist options
  • Save Alan-FGR/fd6175bc10045d33d8542bfc8d8d2e61 to your computer and use it in GitHub Desktop.
Save Alan-FGR/fd6175bc10045d33d8542bfc8d8d2e61 to your computer and use it in GitHub Desktop.
Correct Mixin Example
class Base(object):
def methodX(self):
print "methodX from Base"
def methodY(self):
print "methodY from Base"
class BaseDeriv(Base): #inherits methodX
def methodY(self): #overrides methodY
print "methodY BaseDeriv Override"
class Mixin(object):
def methodX(self):
print "methodX Mixin Override"
class ExampleClass(Mixin,BaseDeriv): #this is the correct order
def methodXfromBase(self):
Base.methodX(self)
def methodsY(self):
Base.methodY(self)
BaseDeriv.methodY(self)
self.methodY() #same as above in this case
inst = ExampleClass()
inst.methodX()
inst.methodXfromBase()
inst.methodsY()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment