Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A new design pattern, the "template mixin"

13 views
Skip to first unread message

Mr Flibble

unread,
Mar 4, 2023, 2:24:35 PM3/4/23
to
Here is an example of a C++ "template mixin", whereby interfaces are
related by inheritance in a way that is covariant to the relationship
between the abstract and concrete classes that implement them.

This new pattern is compatible with the object oriented SOLID principles
and is a way of using single inheritance to avoid the problems associated
with multiple inheritance.

Here the interface classes (denoted by the i_ prefix) are implemented by
the template mixin and the concrete class that derives from it. Note:
inheritance relationships being modeled here are of the "is-a" kind.

struct i_foo
{
virtual void m1() = 0;
};

struct i_bar : i_foo
{
virtual void m2() = 0;
}

template <typename base = i_foo>
struct foo : base
{
void m1() final { /*...*/ }
};

struct bar : foo<i_bar>
{
void m2() final { /*...*/ }
}

/Flibble
0 new messages