Christian Posta bio photo

Christian Posta

Field CTO at solo.io, author Istio in Action and Microservices for Java Developers, open-source enthusiast, cloud application development, committer @ Apache, Serverless, Cloud, Integration, Kubernetes, Docker, Istio, Envoy #blogger

Twitter Google+ LinkedIn Github Stackoverflow

In Python, mixins allow a programmer to package a set of clearly defined and cohesive methods into a unit that can then be used to add functionality to other classes by “mixing in” these methods. This programming style, when used correctly, can lead to well-organized code as well as improved readability. However, in python, there may be better approaches than to use mixins. As Michele Simionato points out in his two part series (part 1 and part 2), python has better constructs for providing the same advantages to using mixins without the drawbacks.

The drawbacks Michele points out include: class namespace pollution, methond-name collisions, accidentally overridden methods, unclear class hierarchy, and cognitive load to understand classes composed of many mixins. To learn more about mixins, see an overview from wikipedia, this post from StackOverflow, this article from Linux Journal and of course the Artima posts from Michele (part 1 and part 2). Michele advises to use this as an alternative: Overloading/Generic Functions