Composition helps in creating large & complex functions by combining small functions. For example, you can build a wall with the help of small bricks. The example of brick may be treated as a function, and composition is all about how we are combining those bricks to make a wall. The Class composition provides us an easy way of composition, including the benefits of composition with Object-Oriented Programming.
You can compose classes and objects. A class may be considered as a “blueprint” for an object, which is an entity that has relevant functions and data (methods and state). It can be used to create many objects depending on the need.
Properties will be added to objects without using inheritance by using the mixin concept. Different object’s properties are mixed into a single object, so the object has all the object’s properties and methods. In other words, a mixin is a way that gives methods that implement a certain behavior. It is used to add the behavior of other classes.
Note: The mixin technique defines some part of behavior, which consists of a factory function which takes a superclass as its argument and returns the respective subclass.
Example: Create a mixin class and by using it develop a “Human” class example.