I
ish
I think this is more of a style question than anything else... I'm
doing a C++ wrapper around a C event library I have and one of the
items is a timer class, I'm also using this task to learn C++.
Is it cleaner to have users subclass my Timer class and implement the
on_timeout() method? Or should the user use a mixin and provide the
mixin to my Timer class?
The subclass method kinda looks like this..
class Timer
{
public:
...
virtual void on_timeout() {};
};
or with a mixin..
class Timer_Mixin
{
public:
virtual ~Timer_Mixin() {};
virtual void on_timeout() = 0;
};
class Timer
{
public:
Timer(Timer_Mixin &mixin);
};
I have both implementations working fine, so its more of a matter of
which style should be preferred.
Thanks.
doing a C++ wrapper around a C event library I have and one of the
items is a timer class, I'm also using this task to learn C++.
Is it cleaner to have users subclass my Timer class and implement the
on_timeout() method? Or should the user use a mixin and provide the
mixin to my Timer class?
The subclass method kinda looks like this..
class Timer
{
public:
...
virtual void on_timeout() {};
};
or with a mixin..
class Timer_Mixin
{
public:
virtual ~Timer_Mixin() {};
virtual void on_timeout() = 0;
};
class Timer
{
public:
Timer(Timer_Mixin &mixin);
};
I have both implementations working fine, so its more of a matter of
which style should be preferred.
Thanks.