Last active
June 17, 2016 03:17
-
-
Save Alan-FGR/fd6175bc10045d33d8542bfc8d8d2e61 to your computer and use it in GitHub Desktop.
Correct Mixin Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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