473,385 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Timer class, mixin vs. subclass.

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.
Sep 13 '06 #1
2 2179
is*@unx.ca wrote:
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.
I tend to look at things like this from a pragmatic point of view. If I
can't really see the advantage of using the separate class, I would
follow Occam's razor and use the simpler way. But it depends really.

It's good to have a few style guidelines when designing, but don't fall
in the so-called analysis-paralysis. It's better to learn from your
mistakes than to try to get everything perfect the first time.

Regards,
Bart.

Sep 13 '06 #2
is*@unx.ca wrote:
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?
Also, look into the way Java AWT/Swing handle events. I, personally,
find that method particularly elegant.

Nate
Sep 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Udo Gleich | last post by:
Hi, I try to implement mixin classes. Thats why I need to make a new class at runtime. --tmp.py------------------------------------- import new class K1(object):
2
by: Florian Preknya | last post by:
Is there a posibility to overwrite a private method (one that starts with __ ) ? I read that they are just formely private, they are prefixed with the class name to have an obtured visibility, so...
3
by: Alexey Klimkin | last post by:
Hello! Is it possible in python to replace base class with another one? Assume an example: class A: def f(self): print 'A' class B(A): def f(self):
12
by: Humpty Dumpty | last post by:
Hello, I'm experimenting with different ways of extending a class (for a plug-ins framework for a GUI) with more than one extension when some of these extensions need to collaborate, but others...
14
by: Curzio Basso | last post by:
Hi all. I have a couple of question regarding the following situation: class A(object): def __init__(self): pass class B(object): def __init__(self):
11
by: Sean Don | last post by:
Hello! Is it possible to make classes friends in Python? Or is it better to just stick to "Java style" .isThis, .getThat, .setThis style functions? I understand that classes are generally...
50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
8
by: digitalorganics | last post by:
Hi all. If I have an instance of class A, called say foo, and I need to mix-in the functions and variables of another class (class B) to this instance at runtime, how do I do it? In other words, I...
2
by: Ninereeds | last post by:
I'm messing around with using mixin-layers (look for papers by Yannis Smaragdakis and Don Batory) to define data structures. One issue is that nodes tend to have pointers to other nodes - the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.