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_Mix in &mixin);
};
I have both implementations working fine, so its more of a matter of
which style should be preferred.
Thanks. 2 2203 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_Mix in &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. 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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):
|
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 maybe it's a trick here...
More details...
I use wxPython, more specifically the wxColumnSorterMixin class. I want to
overwrite the __OnColClick event handler to behave on my way: I want the
sorting feature will affect only some columns, not all...
|
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):
|
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 mustn't know about each
other.
I.e., if I have a class A, and I want to add a block of functionality, I
can derive it into a B that adds that fucntionality. If I want to add more
functionality, I can derive B into a C. But if I want to add a...
|
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):
| |
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 grouped logically into separate files
anyway. So, this isn't always necessary. But I'm a perfectionist and was
wondering if friendships were possible in Python.
Thank you!
|
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
def foo(self, data):
self.attr1=data
self.attr2.append(data)
The initialization of attr1 is obviously OK, all instances of Father
redefine it in the method foo. But the initialization of attr2 is wrong
|
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 want to make foo
an instance of an anonymous and temporary class that inherits its
functionality from classes A and B, while at the same time I want the
pre-existing contents of foo to remain intact. Possible in Python?
Thanks....
|
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 pointers have to
point to the full node type, and have to be referenced before that
full node type is known.
One solution is to use the 'fixpoint construction' to get an apparent
circular dependency...
class c_Final : public c_Layer2< c_Layer1...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |