www.digitalmars.com         C & C++   DMDScript  

D - What's a Mixin?

reply "Craig Black" <cblack ara.com> writes:
On the Future Directions page on the D website, three features are
presented.  One of which is "Mixins", something that I have never heard of
before.  Would someone care to explain what this is?

Thanks,

Craig
Mar 29 2004
next sibling parent "Achilleas Margaritis" <axilmar b-online.gr> writes:
"Craig Black" <cblack ara.com> wrote in message
news:c4a46g$jg9$1 digitaldaemon.com...
 On the Future Directions page on the D website, three features are
 presented.  One of which is "Mixins", something that I have never heard of
 before.  Would someone care to explain what this is?

 Thanks,

 Craig

A mixin is the result of mixing two or more classes together. In C++, for example, 'fstream' is a mixin of 'ifstream' and 'ofstream'. Mixins can be done by multiple inheritance or by aggregation.
Mar 29 2004
prev sibling parent reply "Derek Parnell" <Derek.Parnell psyc.ward> writes:
On Mon, 29 Mar 2004 15:24:31 -0600 (30/Mar/04 07:24:31 AM)
, Craig Black <cblack ara.com> wrote:

 On the Future Directions page on the D website, three features are
 presented.  One of which is "Mixins", something that I have never heard  
 of
 before.  Would someone care to explain what this is?

 Thanks,

 Craig

I understand it to mean the process of creating a new class by picking out attributes and methods from two or more other classes. A bit like multiple inheritence but instead of getting everything, you get to pick which parts you want to inherit. I could be wrong though. -- Derek
Mar 29 2004
parent reply larry cowan <larry_member pathlink.com> writes:
Here are some references.  We have a lot of the concept, but there seem to be
some things missing.  Maybe someone else can fill that in better than I...

In approximate order of increasing scope and generality:

http://www.cs.utexas.edu/users/richcar/JLMixins.html
http://c2.com/cgi/wiki?MixIn
http://cpptips.hyperformix.com/cpptips/mixins
http://www-106.ibm.com/developerworks/java/library/j-diag1203/
http://www.rubycentral.com/book/tut_modules.html
http://www.cs.utexas.edu/users/richcar/fidget.pdf
http://www.iam.unibe.ch/~scg/Teaching/IOOM/PPT/VariationOnInheritance.pdf


In article <opr5ndv0f4u2m3b2 news.digitalmars.com>, Derek Parnell says...
On Mon, 29 Mar 2004 15:24:31 -0600 (30/Mar/04 07:24:31 AM)
, Craig Black <cblack ara.com> wrote:

 On the Future Directions page on the D website, three features are
 presented.  One of which is "Mixins", something that I have never heard  
 of
 before.  Would someone care to explain what this is?

 Thanks,

 Craig

I understand it to mean the process of creating a new class by picking out attributes and methods from two or more other classes. A bit like multiple inheritence but instead of getting everything, you get to pick which parts you want to inherit. I could be wrong though. -- Derek

Mar 29 2004
parent resistor mac.com writes:
To me it seems a lot like the Objective-C concept of categories.  In ObjC, it
goes like this:  I can define 
a category of any existing class, which can add methods to any pre-existing
class.  From then on, any 
code that imports my category sees my methods on the class as indistinguishable
from those defined 
within the class itself.

Example:

There's a class called NSData for holding binary data.  I want it to be able to
use it for GZIP 
compression, so I write a category that adds zip() and unzip() methods to it,
and place it in 
NSData+Gzip.h.  Then any code that has a "#include NSData+Gzip.h" will see the
zip() and unzip() 
methods as if they were part of the class itself.

Ok, that was somewhat random, but it's another approach to the same basic
problem, and perhaps an 
interesting idea for D.

Owen

In article <c4ags8$19tu$1 digitaldaemon.com>, larry cowan says...
Here are some references.  We have a lot of the concept, but there seem to be
some things missing.  Maybe someone else can fill that in better than I...

In approximate order of increasing scope and generality:

http://www.cs.utexas.edu/users/richcar/JLMixins.html
http://c2.com/cgi/wiki?MixIn
http://cpptips.hyperformix.com/cpptips/mixins
http://www-106.ibm.com/developerworks/java/library/j-diag1203/
http://www.rubycentral.com/book/tut_modules.html
http://www.cs.utexas.edu/users/richcar/fidget.pdf
http://www.iam.unibe.ch/~scg/Teaching/IOOM/PPT/VariationOnInheritance.pdf


In article <opr5ndv0f4u2m3b2 news.digitalmars.com>, Derek Parnell says...
On Mon, 29 Mar 2004 15:24:31 -0600 (30/Mar/04 07:24:31 AM)
, Craig Black <cblack ara.com> wrote:

 On the Future Directions page on the D website, three features are
 presented.  One of which is "Mixins", something that I have never heard  
 of
 before.  Would someone care to explain what this is?

 Thanks,

 Craig

I understand it to mean the process of creating a new class by picking out attributes and methods from two or more other classes. A bit like multiple inheritence but instead of getting everything, you get to pick which parts you want to inherit. I could be wrong though. -- Derek


Mar 29 2004