I've create a base class for Packages that I am sending via TCP/IP, and
then deriving the different transport classes from this base class.
Now I can recreate the classes on the other end with the correct class
type, but each package will need to be passed back to a different
handling function that is not known to the transmitting program, and
may change.
Here's my question:
How should I implement handling the routing of the package on the
receiving program? I could use a switch statement to route them, which
would solve the problem, but defeats polymorphism and is evil.
However, if I add it to an overridden function such as Route() to the
Package class, it adds a dependancy to other files that the client
program may not have.
How would you pros go about handling this situation?
Thanks,
Josh McFarlane 2 1257
Josh Mcfarlane wrote: I've create a base class for Packages that I am sending via TCP/IP, and then deriving the different transport classes from this base class.
Now I can recreate the classes on the other end with the correct class type, but each package will need to be passed back
"back"?
to a different handling function that is not known to the transmitting program, and may change.
Are you saying that Package is returning to your transmitting program,
to be handled?
Here's my question:
How should I implement handling the routing of the package on the receiving program?
There should probably be some kind of 'PackageHandler ' class, from which
you could derive 'PackageOneHand ler' and 'PackageTwoHand ler', depending on
the overall variety of packages you have...
I could use a switch statement to route them, which would solve the problem, but defeats polymorphism and is evil.
It probably does. You still have to have a switch statement somewhere,
don't you? I mean, you receive a bunch of bytes and then what? You gotta
look at some bytes and then branch somehow based on their value... But
that's not the problem I guess. Well, the usual way is probably to have
some sort of registry for the Package type ID and the handler. Once you
have a handler instantiated, it should register itself in the registry so
next time a package arrives, that handler is called upon to handle the
package (or the package gets stuffed in its queue or something).
However, if I add it to an overridden function such as Route() to the Package class, it adds a dependancy to other files that the client program may not have.
That implies that Package should handle itself. I don't think it's right.
How would you pros go about handling this situation?
I don't know. Not enough detail available. A registry of queues for the
arriving packages and queue workers (handlers) should probably take care
of the most dynamic situation there is.
V
Victor Bazarov wrote: "back"? Are you saying that Package is returning to your transmitting program, to be handled?
Sorry, bad usage of words, I meant after the package is recreated on
the receiver, it has to be dealt with. It is a new package from the
perspective of the receiving computer.
There should probably be some kind of 'PackageHandler ' class, from which you could derive 'PackageOneHand ler' and 'PackageTwoHand ler', depending on the overall variety of packages you have... [...] It probably does. You still have to have a switch statement somewhere, don't you? I mean, you receive a bunch of bytes and then what? You gotta look at some bytes and then branch somehow based on their value... But that's not the problem I guess. Well, the usual way is probably to have some sort of registry for the Package type ID and the handler. Once you have a handler instantiated, it should register itself in the registry so next time a package arrives, that handler is called upon to handle the package (or the package gets stuffed in its queue or something).
You know, I think this is what I was trying to head towards, but for
some reason thought that I had to incorporate the handler into the
package itself.
Creating a map of functions and PackageTypeIDs would solve this problem
and allow me to deal with this in a reliable way. Just wanted to make
sure I wasn't missing a way to use polymorphism vs switch statements.
Thanks for your advice,
Josh McFarlane This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Myster Ious |
last post by:
Polymorphism replaces switch statements, making the code more
compact/readable/maintainable/OO whatever, fine!
What I understand, that needs to be done at the programming level, is
this:
a switch-case has a variable (most probably an enumeration) &
associated symbols or integral value. Selection is made, base on what
symbol/value the variable holds. So
|
by: Ken |
last post by:
Hi.
Can anyone refer me to any articles about the compatibility between
c++ polymorphism and real-time programming?
I'm currently on a real-time c++ project, and we're having a
discussion about whether we should allow polymorphism. Our system is
not embedded and does not need to be as real-time as, say, a
pacemaker. But it does involve updating displays based on radar
input. So a need for something close to real-time is desired...
|
by: Patchwork |
last post by:
Hi Everyone,
Please take a look at the following (simple and fun) program:
////////////////////////////////////////////////////////////////////////////
/////////////
// Monster Munch, example program
#include <list>
|
by: Jacek Dziedzic |
last post by:
Hello!
First of all please forgive me for not posting a compilable snippet,
but rather a simplified piece of code with the unimportant
details left out.
Let's say I have two classes 'box_shape' and 'cylinder_shape' that
derive from a common base class 'shape', more or less like this:
namespace Shapes {
|
by: Leslaw Bieniasz |
last post by:
Cracow, 20.09.2004
Hello,
I need to implement a library containing a hierarchy of classes
together with some binary operations on objects. To fix attention,
let me assume that it is a hierarchy of algebraic matrices with the
addition operation. Thus, I want to have a virtual base class
class Matr;
| |
by: enchantingdb |
last post by:
I have an exam tomorrow that covers the perceived advantages and
disadvantages of object oriented programming, in particular
polymorphism, inheritance and encapsulation. I know the advantages but
am not clear on the disadvantages. I have had a look on the Web and in
newsgroups but couldn't find much. As time is running out, I thought I
would post here and hope that someone would reply.
Thanks
Rob
|
by: Krivenok Dmitry |
last post by:
Hello all!
Perhaps the most important feature of dynamic polymorphism is
ability to handle heterogeneous collections of objects.
("C++ Templates: The Complete Guide" by David Vandevoorde
and Nicolai M. Josuttis. Chapter 14.)
How to implement analogue of this technique via static polymorphism?
Perhaps there is special design pattern for this purpose...
|
by: Seigfried |
last post by:
I have to write a paper about object oriented programming and I'm doing
some reading to make sure I understand it. In a book I'm reading,
however, polymorphism is defined as:
"the ability of two different objects to respond to the same request
message in their own unique way"
I thought that it was:
"the ability of same object to respond to different messages in
|
by: weaknessforcats |
last post by:
Introduction
Polymorphism is the official term for Object-Oriented Programming (OOP). Polymorphism is implemented in C++ by virtual functions.
This article uses a simple example hierarchy which you may have seen many times in one form or another. An analysis of this example produces several problems that are not obvious but which will seriously limit your ability to use hierarchies like the example in a real program. Then, the article...
|
by: feel |
last post by:
Hi,All
I am sure it's an old question. But I just find a interesting design
about this: Polymorphism without virtual function in a C++ class.
My solution is for some special case, trust me, very special.
1 single root class tree
2 the leaf(lowest level) classes are sealed which means we should not
inherite class from them.
3 PImpl idiom. There is only one data mumber in root class and there
is no any other data mumber in child class and...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |