I'm working on a scheme which reduces the interface between classed to a single method and a list messages that the co-operative class knows. I invite all comments and/or critiques/improvements: We could even turn this into an article! - class AnyClass(object):
-
"""Demonstrate massage passing:
-
This is the subordinate class."""
-
def Funct1(self, arg1):
-
print "AnyClass.Funct1 got", arg1
-
self.Send("MESSAGE3", arg1, string1='hello', string2='world')
-
-
def Funct2(self, arg2, arg3):
-
print arg2, arg3
-
-
def Funct3(self, count, **kwargs):
-
"""Must document the names of the kwargs here:
-
Funct3(count, string1, string2)"""
-
print count, kwargs['string1'], kwargs['string2']
-
-
-
# Of cource, the sender and the reciver would typically have different massages
-
DispatchDict = {'MESSAGE1':Funct1, 'MESSAGE2':Funct2, 'MESSAGE3':Funct3}
-
-
def Receive(self, *args, **kwargs):
-
self.DispatchDict[args[0]](self, *args[1:], **kwargs)
-
-
def Connect(self, callback):
-
self.Send = callback
-
return self.Receive
-
-
-
class AnyOtherClass(object):
-
"""Demonstrate massage passing:
-
This is the superior class."""
-
def __init__(self):
-
self.Worker = AnyClass()
-
self.Send = self.Worker.Connect(self.Receive)
-
self.Send('MESSAGE1', 5)
-
-
def Funct1(self, arg1):
-
print arg1
-
-
def Funct2(self, arg2, arg3):
-
print arg2, arg3
-
-
def Funct3(self, count, **kwargs):
-
"""Must document the names of the kwargs here:
-
Funct3(count, string1, string2)"""
-
print count, kwargs['string1'], kwargs['string2']
-
-
-
# Of cource, the sender and the reciver would typically have different massages
-
DispatchDict = {'MESSAGE1':Funct1, 'MESSAGE2':Funct2, 'MESSAGE3':Funct3}
-
-
def Receive(self, *args, **kwargs):
-
self.DispatchDict[args[0]](self, *args[1:], **kwargs)
-
-
test = AnyOtherClass()
-
0 1407 Sign in to post your reply or Sign up for a free account.
Similar topics
by: cold |
last post by:
I'm trying to write an helper class that allows me to serialize objects to a
socket (or a NetworkStream). I know there are plenty of .NET classes that
help me to serialize object to an array of...
|
by: Gvs |
last post by:
Hi,
I'm currently trying to pass messages into a queue. This all works fine,
however, i'm trying to my program to stop sending messages to the queue when
it reaches an upper threshold. At...
|
by: Schorschi |
last post by:
Can someone please point out why I am getting an 87 error? I am sure
it is obvious, but I am new to C# and seem to be having a lot of
stress understanding managed versus unmanaged code when API...
|
by: Adam |
last post by:
Hi,
How do i listen for windows messages in c# on
compact.net? I have a window containing an instantiation
of the HTML viewer control, which is a child of the main
form. As the compact...
|
by: Arsen Vladimirskiy |
last post by:
Hello,
If I have a few simple classes to represent Entities such as Customers and
Orders.
What is the proper way to pass information to the Data Access Layer?
1) Pass the actual ENTITY to...
|
by: Curious |
last post by:
Hi,
I need some technique to communicate by passing messages with different
threads. For my problem shared memory is not applicable.
Can someone give me some help of what there is available...
|
by: Stan |
last post by:
There are two ways to pass structured data to a web service:
xml
===
<Order OrderId="123" OrderAmount="234" />
or class
=====
|
by: Andrew Bullock |
last post by:
Hi,
I have two classes, A and B,
B takes an A as an argument in its constructor:
A a1 = new A();
B b = new B(a1);
|
by: AAaron123 |
last post by:
On a Form I have a RichTextBox.
I do the call for EM_SETEVENTMASK with ENM_REQUESTRESIZE
The user control's WndProc writes to the consol to keep track of any
EN_REQUESTRESIZE messages.
As...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |