I'd like to submit a code pattern I often see in my python code, here at work, and I'm not satisfy with it and I'd like a better solution.
Here is what we have today:
class AbstractClass(object):
....
def method1(self,...)
raise NotImplementedError
...
class FirstImplementationMixin(object)
def method1(self,....)
...
class SecondImplementationMixin(object)
def method1(self...)
....
class InstanciatedClass1(FirstImplementationMixin, AbstractClass)
....
class InstanciatedClass2(SecondImplementationMixin, AbstractClass)
....
Do you see the trick? I have to add the mixin at first position in the list of the inheritance, and I don't like this solution. If we add it at the second position, the interpreter will use AbstractClass.method1 and so raise the exception.
In this trivial situation, replacing the mixin by intermediate class is possible, but in case of complex inheritance with already a base class, the solution might not be obvious.
What is for you the best design pattern?