Sometimes using mixin with multiple inheritance can help us improve reusability of our code.
For example, the following design
class FollowableMixin(object):
def get_followers(self):
...
...
class User(FollowableMixin):
...
may be better reused than simply adding get_followers
to User
:
class User(object):
def get_followers(self):
...
...
because later we may consider supporting other followable entities that are potential clients of get_followers
:
class BookStore(FollowableMixin):
...
However, if this pattern is overused, code may get too complex.
class User(FollowableMixin, RunnableMixin, FlyableMixin, WhatMixin ...):
...
With all these mixin classes injecting properties and methods to your class, it becomes very difficult to understand your code. For example, you don't know where the method you are calling is from, and this method may in turn include an invocation of a method in another mixin ...
What should I do to simplify this programme?