So what's the difference between a mixin and an abstract base class?
Crossbones+ - Reputation: 3306
Posted 03 September 2012 - 02:51 PM
So what am I missing here?
Beginner in Game Development? Read here.
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts
Members - Reputation: 3331
Posted 03 September 2012 - 04:39 PM
In general, a mix-in is a standalone set of functionality that is tacked onto something, whereas an abstract base class represents a incomplete implementation of a core concept. In C++ (and a few other languages), these are done using the same construct. From a design perspective and from a conceptual perspective they're different.
Members - Reputation: 468
Posted 04 September 2012 - 05:08 AM
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.