Mixin

A mixin is a class which contains a combination of methods from other classes without using inheritance.

Python Example

Python mixins are inheritance.
The class name usually contains ‘Mixin’.

# Define a mixin class.
class MixinExample:
    def set_name(self, name_to_set):
        self.name = name_to_set            
    def get_name(self):
        return self.name

# Define a class that inherits the mixin.
class ClassExample(MixinExample):
    
    # Define the constructor.
    def __init__(self):
        self.name = "Default"

# Instantiate an object using the ClassExample.
class_example = ClassExample( )
 
# Use the mixin get_name method.
class_example.set_name("Mark")
name_example = class_example.get_name( )
print(name_example)