From: Leigh Johnston on
"Andy Venikov" <swojchelowek(a)gmail.com> wrote in message
news:i0vvpg$2ee$1(a)news.eternal-september.org...
>
> Mix-ins are classes that inherit from a template parameter.
>

No, a mixin is a class which must be inherited from that provides both an
interface to be overriden and an implementation.

/Leigh


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Andy Venikov on
Leigh Johnston wrote:

>
> No, a mixin is a class which must be inherited from that provides both
> an interface to be overriden and an implementation.
>
> /Leigh
>

Ok, to be strictly general, a mix-in is a concept that splits different
roles or functionalities into separate entities (classs, objects, meta
functions, you name it) and then uses any combination thereof to achieve
desired behavioral effect. Similar to policies.

But in C++ community, a mixin refers to a very specific way to implement
a general mix-in concept.

It can be implemented using a CRTP, a multple inheritance or a C++
mixin. C++ "mixin" implementation of a mixin concept uses an abstract
subclass as opposed to an abstract superclass.

I.e.

template <typename Base>
class MixIn1 : public Base
{
};

This way you can extend Base's functionality without modifying the Base
class. The power of mix-ins comes from the ability to layer mix-ins:

template <typename Base>
class MixIn2 : public Base
{...};

class MyClass {...};

typedef MixIn2<MixIn1<MyClass> > MyClassExtendedWithMixIn1AndMixIn2;

The OP's example was using a classic CRTP to implement the general
Mix-in concept, not a C++ mixin.

If you google on C++ mixins, all relevant links on the first two pages
describe the abstract subclass model. The only doc that I could find
that talks about a mixin in terms of a superclass was a wikipedia page.
But that page was totally C++ agnostic.


Thanks,
Andy.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: DeMarcus on
On 2010-07-07 04:19, Mathias Gaunard wrote:
> On Jul 6, 8:15 pm, DeMarcus<use_my_alias_h...(a)hotmail.com> wrote:
>> Hi,
>>
>> As I understand, Policies have been widely accepted, but is it the same
>> with Mixins? Or does people still believe Mixin is a bad way to avoid
>> Liskov's IS-A principle?
>>
>> My latest Mixin looks like this.
>>
>> template<class T>
>> class CopyMixin
>> {
>
> template<typename T, typename Base = some_empty_class_type>
> class CopyMixin : Base
> {
>
> is better since it allows you to avoid multiple inheritance.
>
>

Thanks! But could you please explain that. First I don't understand what
some_empty_class_type is and what it brings. I also don't understand
what you mean with avoiding multiple inheritance and why that is necessary.

Thanks for your time!

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: DeMarcus on
{ Please include appropriate attribution, such as "John Doe wrote:",
for the quoted material. -mod }

>
> Ok, to be strictly general, a mix-in is a concept that splits different
> roles or functionalities into separate entities (classs, objects, meta
> functions, you name it) and then uses any combination thereof to achieve
> desired behavioral effect. Similar to policies.
>
> But in C++ community, a mixin refers to a very specific way to implement
> a general mix-in concept.
>
> It can be implemented using a CRTP, a multple inheritance or a C++
> mixin. C++ "mixin" implementation of a mixin concept uses an abstract
> subclass as opposed to an abstract superclass.
>

That was /very/ enlightening. Thanks! You should update Wikipedia with
that information. (I could do it as well, but you must have the cred for it)


So, to sort out all ways of customization we have the following list. If
anyone has an opinion, please fill in or comment.

1. Pure virtual interfaces - used to customize a class' interface but
provides no functionality.

2. Multiple inheritance - used to customize a class' interface and
provide functionality that is not dependent on the customized class' type.

3. C++ mixin - used to customize a class' interface and provide
functionality where the base class cannot be modified.

4. CRTP - used to customize a class' interface and provide functionality
where the functionality is dependent on the customized class' type.

5. Policies - used to customize a template's interface and provide
functionality where the functionality is dependent on the customized
template's provided type T.


Item 1 is seen as design-by-contract whereas items 2-5 are seen as ways
to implement the general Mix-in concept.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Leigh Johnston on
"Andy Venikov" <swojchelowek(a)gmail.com> wrote in message
news:i12psg$tip$1(a)news.eternal-september.org...
> Leigh Johnston wrote:
>
>>
>> No, a mixin is a class which must be inherited from that provides both an
>> interface to be overriden and an implementation.
>>
>> /Leigh
>>
>
> Ok, to be strictly general, a mix-in is a concept that splits different
> roles or functionalities into separate entities (classs, objects, meta
> functions, you name it) and then uses any combination thereof to achieve
> desired behavioral effect. Similar to policies.
>
> But in C++ community, a mixin refers to a very specific way to implement
> a general mix-in concept.
>
> It can be implemented using a CRTP, a multple inheritance or a C++
> mixin. C++ "mixin" implementation of a mixin concept uses an abstract
> subclass as opposed to an abstract superclass.
>
> I.e.
>
> template <typename Base>
> class MixIn1 : public Base
> {
> };
>
> This way you can extend Base's functionality without modifying the Base
> class. The power of mix-ins comes from the ability to layer mix-ins:
>
> template <typename Base>
> class MixIn2 : public Base
> {...};
>
> class MyClass {...};
>
> typedef MixIn2<MixIn1<MyClass> > MyClassExtendedWithMixIn1AndMixIn2;
>
> The OP's example was using a classic CRTP to implement the general
> Mix-in concept, not a C++ mixin.
>
> If you google on C++ mixins, all relevant links on the first two pages
> describe the abstract subclass model. The only doc that I could find
> that talks about a mixin in terms of a superclass was a wikipedia page.
> But that page was totally C++ agnostic.
>
>

Restricting the definition of a mixin to a particular C++ implementation
that uses a particular C++ feature (templates) is incorrect, it is like
defining "fruit" to be "an apple". Using multiple inheritance is an equally
valid way of implementing a mixin in C++ so my definition was correct whilst
yours was not really a definition at all.

/Leigh


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]