By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

Generic communications module with a little help from classes...

P: n/a
What I want to do is create a module that offers a generic set of
functions (send, recieve, etc...) and reffers the request to the
correct module (rs-232, tcp/ip, etc..).
I want all this to be unseen by the script that calls this module.
I want the script to specify the communication type, and then be able
to use the functions. In the future, when the whole script will work on
a different type of communication all that will be changed is the type
of communication property.
How do I do this?

I thought of a few possibilities:
1. all communication modules will have the same function names and same
number of params (problematic), and then it will look like this:

class module1:
def send(self):
# send one way

class module2:
def send(self):
# send the other
if X:
selected = module1
selected = module2

class main(selected):

m = main()

2. the other option is creating a "wrapper" class for each module. this
class takes the generic params of the function "send" and organizes the
params and name so it will be compatible with the comm module:

class a:
def send(self, what):

class b:
def send(self, what):

if X:
selected = a
selected = b

class main(selected):

m = main()

which way is better? any better ideas?


Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.