mercredi 27 février 2019

Multi inheritance and design pattern

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.

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 Bar:
   def bar(self, x):
       return x

class Foo:
   def foo(self, x):
       return self.bar(x)

class Test(Foo, Bar):
   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 ?

Aucun commentaire:

Enregistrer un commentaire