Reputation: 5006
In the facebook-python-business-sdk library, I've seen something that I thought it was bad practice :
AdAccountUserMixin's get_pages() method uses self.iterate_edge() which is neither a method of this class nor a parent's.
AbstractCrudObject implements this method.
And then, AdAccountUser inherits from these two classes. That's why an object of AdAccountUser can use the method get_pages().
Minimal example :
class AbstractBar:
def bar(self, x):
return x
class Foo:
def foo(self, x):
return self.bar(x)
class Test(Foo, AbstractBar):
def test(self, x):
return self.foo(x)
t = Test()
t.test(5) # returns 5
Is this a design pattern, something that you see everyday or just a bad practice ?
Upvotes: 0
Views: 445
Reputation: 77912
That's quite ordinary mixin class stuff. A mixin class is a class that is explicitely designed to complement a given base class or interface (it explicitely relies on the class it's "mixed-in" with to implement a given interface). This is quite useful when you want to factor out some common behaviour from a bunch of classes that implement the same interface without having a common ancestor.
Upvotes: 1