What is the difference between an abstract class and a mixin?

I just found an article on a structure in Java that apparently allows it to support Mixins and something like Composite Oriented Programming (which for everyone I know might even be the same) ... I also heard / worked with AOP and I'm not sure how it differs from this either ...

+13
abstract-class mixins qi4j cop apache-zest
Feb 26 '09 at 16:48
source share
2 answers

In the agnostic language, mixin simply adds functionality to the class and is more suitable for the convenience of programmers and avoids code duplication. An abstract (base) class forms an is-a relation and allows polymorphism. One of the reasons for abuse of inheritance is that it is an easy way to implement mixins without writing a template in languages ​​that do not actually support them. The problem is that you are claiming that polymorphism is a relationship as a side effect, which makes your API more confusing and possibly adds ambiguity. Therefore, newer languages, such as D and Ruby, support mixins as native functions, which makes it convenient to add a bunch of functionality to the class without declaring polymorphic relationships.

+23
Feb 26 '09 at 16:54
source share
β€” -

Mixin is never meant to be an independent class. They just add some functions to the class you declare. In Python, they can be easily applied by class decorators. For example, you can decorate your class with Singleton mixin, making your class a single.

0
Feb 26 '09 at 17:35
source share



All Articles