MI is not evil - it is just a different concept...

Yigal Chripun yigal100 at gmail.com
Fri Dec 26 11:36:58 PST 2008

The User wrote:
> Java allows only a few concepts and design-patterns like MVC or Delegation and polymorphism. But there is not one correct and one wrong design-pattern. D tried to accept more concepts like templates and mixins, you could also accept MI.
> Policy-based Design (http://en.wikipedia.org/Policy-Based_Design) is a very powerful, modern and flexible design-pattern wich makes usage of MI.
> STL and Boost use MI and are excellent designed.
> Features cannot be evil, but they can be used in a wrong way. MI would allow more flexibility, sometimes more elegant code and more design-patterns.
> D is not a prototype anymore, now it could add new features,  http://www.pmg.lcs.mit.edu/papers/bidirectional.pdf shows us, how it could work.
> The User

MI is in fact evil. especially the C++ kind.
there are two concepts conflated here - subtyping and subclassing. They 
shouldn't be connected but they in fact are. MI aggravates this a 
thousand fold.

the first is subtyping:
you want to model your objects such that they'll be subtypes of two 
different types, for example. Java/C#/D easy solution:
interface A {..}
interface B {..}

interface/class ident : A, B {..}
you want to subclass two types (i.e copy the implementation)
Easy in D:
template A {..}
template B {..}
class ident { mixin A; mixin B; ..}

you want to do both (which is what C++ MI does):
class ident : A, B {
mixin impl_A;
mixin impl_B;

here, D supports MI. without all the problems in C++
C++ style MI is EVIL exactly because it conflate two separate concepts 
into one.

If you explore C++ use of MI you'll see that 95% of cases it is used to 
do the subtyping (interfaces). and doing subclassing with it is very 
rare and usually discouraged due to complexity.

More information about the Digitalmars-d mailing list