I've been grappling with how to better structure a large class in Python. It contains essential core functionalities along with various methods that are more specific and dependent on those core methods. I'm curious about the best approach to extract those specific methods and relocate them. In Rust, traits provide a neat solution for this, so I'm wondering what the best practices are in Python to achieve similar functionality.
1 Answer
What you're looking for is known as "composition." In Python, this allows you to embed one object within another class and link their methods as needed. Unlike Rust or Go, Python doesn't rely heavily on this concept, but using mixins might achieve what you want! Just remember, this is a common pitfall in OOP practices.

I get that, but I'm wondering if there's a workaround in more traditional OOP styles. Should I just keep all methods within the class or perhaps use some wrapper class?