I just found an article on a framework in Java that apparently allows it to support Mixins and something called Composite Oriented Programming (which for all I know might even be the same thing...) I've also heard of/worked with AOP, and I'm not sure how it differs from this either...
Asked
Active
Viewed 4,028 times
1 Answers
28
At a language-agnostic level, a mixin just adds functionality to a class, and is more for programmer convenience and to avoid code duplication. An abstract (base) class forms an is-a relationship and allows for polymorphism. One reason why inheritance is overused is that it's an easy way to implement mixins without writing any boilerplate in languages that don't really support them. The problem is that you're declaring a polymorphic is-a relationship as a side effect, making your API more confusing and possibly adding ambiguity. Hence, newer languages like D and Ruby support mixins as native features, allowing a convenient way to add a bunch of functionality to a class without declaring a polymorphic is-a relationship.

dsimcha
- 67,514
- 53
- 213
- 334
-
+1 Good brief explanation. This COP stuff sounds cool. Although I like to see this kind of thing work its way down to the core language level. Same with AOP stuff. – BuddyJoe Feb 26 '09 at 17:01
-
@Bruno A core language like C++? – leeand00 Feb 26 '09 at 19:43
-
I think the point about making an incorrect/unnecessary 'is-a' relationship is a good point. – mklauber Sep 18 '12 at 17:42
-
The mentioned "framework" (Qi4j) by the OP, is now [Apache Zest](http://zest.apache.org). – Niclas Hedhman Dec 12 '15 at 02:45
-
1And what are the downsides of the "is-a" relationship we are trying to avoid through mixins? – Aykhan Hagverdili Feb 23 '22 at 12:04