CRTP (Mixins)
Explore the Curiously Recurring Template Pattern (CRTP) as a method to implement mixins in C++. Understand how CRTP allows static polymorphism by inheriting common functionality and reducing boilerplate, such as operator overloading, and how this idiom contrasts with dynamic polymorphism in Python.
We'll cover the following...
Mixins
Mixins are a class with methods that can be used by classes even if they’re not derived from them. It’s a popular idea when designing classes to mix in new code. Therefore, it’s a technique often used in Python to change the behavior of a class by using multiple inheritances. In contrast to C++, it’s legal in Python to have more than one definition of a method in a class hierarchy. Python simply uses the method that’s first in the Method Resolution Order (MRO).
Example
We can implement ...