View mode: basic / threaded / horizontal-split · Log in · Help
May 05, 2004
Re: COMMENTS: Mixins Specification
"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message
news:c79osk$2ggk$1@digitaldaemon.com...
> Matthew wrote:
> >>Could I say that the Ranges mixin could also be (hackishly) implemented
> >>like this:
> >>
> >>class Range(C) : C
> >>{
> >>    ...various fields here...
> >>}
> >>
> >>
> >>And then the class which mixes it would be defined like this:
> >>
> >>
> >>template ListBase(T,B)
> >>{
> >>   public class List
> >>         : B                      // base class
> >>         , mixes Ranges    // Note: do not need to specify mixing class,
> >>     {
> >>     }
> >>}
> >
> >
> > Yes
> >
> >
> >>// Can you use the template shortcut syntax for a typedef?
> >>// If so, a typedef would be better hre.
> >>template class List(T, B = EmptyBase) : Range(ListBase(T,B)) {};
> >>
> >>
> >>Obviously, this is a more hackish solution, plus it has more class
> >>overhead.  Also, in this scenario, Range cannot provide implementations
> >>for members of interfaces that List might want to export.  But
> >>otherwise, does it accomplish nearly the same purpose?
> >
> > Sorry, dude, I just don't get it. Can you explain this example more
thoroughly?
>
> What I was trying to illustrate is that you can define a template which
> adds member functions to an existing class, which is sort of like a
> mixin.  However, I like your mixin syntax because
> 1) Looks cleaner
> 2) You only declare 1 class, rather than 3 (List rather than
> List->Range(ListBase)->ListBase)
> 3) In your mixin definition, you can have List implement an interface
> which includes some functions from List and some from Range.  This is
> not possible with the template solution.
>

Mixins can be a different construct, like a struct/class/interface.
Next ›   Last »
1 2 3
Top | Discussion index | About this forum | D home