What is a mix?

In computer programming, a mix class that is inherited by another class but is not intended for an instance. One class can inherit many mixers, so many collections of features can be easily consolidated. Although many common programming languages ​​use mixin methodology, there are many others that not, including C ++ and Java. In general, mixers are found in scripting languages ​​or in languages ​​that have the ability to create scripts such as JavaScript and Perl.

Mixins are unique in becoming part of a subclass during compilation. Their methods and constants are included in the subclass. Another unique feature of the mix class is that the methods can be defined and tied to objects. Most languages ​​use different approach, bindings and defining methods at the time of compilation rather than running. This Runtime binding allows mixers to be very flexible.

common problem in multiple heritage is manyThe consideration of calling methods and mixers can solve this problem because they do not follow exactly the same rules as multiple inheritance. For example, multiple inheritance can create a so -called "death diamond" where the parent class A has B and C and C -class D inherit from both classes B and C. The problem in this scenario is that methods that have the same name A, B and C can be inherited in class D. Mixins solve this problem by keeping them clearly. Multiple heritage.

Mixins will not overwrite the methods in the classrooms in which they are inherited. For example, if Class A defined the "Mymethod" and inherited method, which also defined the "Mymethod" method, both of these methods could still be called without ambiguity and the implementation of "mymethod" in class and class to be completely accessible. Exactly how these methods would be called depends on the language in which the mix is ​​implemented.

Some programming languages ​​that nepThey use mixers like Java, imitating the interface. The interfaces in these languages ​​do not imitate the full functionality of mixers, as the interfaces can only contain constants and statements of methods. Mixins, on the other hand, contain complete methods of methods. Those languages ​​that do not support mixers often have viable alternatives that can be forced to do about the same thing.

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?