So what's the difference between a mixin and an abstract base class?

Started by
1 comment, last by GlenDC 11 years, 7 months ago
Based on everything that I've read on both, they seem to do the exact same thing. They both can be inherited but not instantiated. They're both for code reuse. They both provide implementations and can be used polymorphically.

So what am I missing here?

Beginner in Game Development?  Read here. And read here.

 

Advertisement
In certain languages, a mix-in or trait has special limitations that allow it to be multiply inherited sanely.

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.
Found some useful websites that may help you:
A quote from dsimcha on another webpage:
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.[/quote]

This topic is closed to new replies.

Advertisement