bartonc 6,596
Recognized Expert Expert
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 1440 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 byte, but I can't undestand how I
can send a block of bytes and being sure the receiver will receive only this
block....I mean, if I write the bytes to a NetworkStream the receiver will
get a stream of bytes and he won't have any way to know how to...
|
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 present this threshold is the number of
chairs in a waiting room. This is an int represented by nChairs.
So i want to compare this to the number of messages in my queue. I'm using
the following lines of code to do this, however the queue is always...
|
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 calls are
needed!
//
using System;
using System.Runtime.InteropServices;
|
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 implementation of the form class
does not have a wndproc function to override, i cannot
get the messages. I cannot use a message window, as the
window i am listening to will then not display.
Is there another method of doing this?
|
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 the Data Access Layer method
-or-
2) Pass some kind of a unique id to the Data Access Layer method
| |
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 in the .net.
Thanks in Advance
|
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 I type into the RichTextBox I see the results of the console writes in
the Output window.
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: 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...
| |