Sometimes using the mixin with multiple inheritance, we need to reuse our code May help improve.
For example, the following design
class indexed mixes (object): def get_followers (self): ... ... class user (followmixin): ..
user: > get_followers
touser
:class user (object): instead of adding def get_followers < P> Better re-use (self): ... ...
Because later we may consider supporting other indexable entities, NO of code> get_followers
However, if the pattern is overuse, the code can be very complex.
However, if this pattern is overUvauver, the code can be very complex.
Class users (transitive mixes, runonable mixes, flawless mixes, vatomcins ...): ...
All of these mixing classes with their class With the injection of properties and methods in it, it becomes very difficult to understand your code. For example, you do not know how you are calling, and this method may include the invocation of a method in another mix ...
Let me simplify this program What to do?
Sometimes it can help to collect relevant features in the same class if They often use together.
Then when you come to use it, instead of many, only one or two straight bases The class is
Obviously you should do this, if it makes sense - it can be misused, without knowing more about your specific example, it is very difficult to know whether it is in your case Whether it is understandable or not?
Comments
Post a Comment