Moving Data within an Application
-
I am in the process of creating a communications server for an application we are building. Pretty standard architecture, multi-threaded, server waits for connection from remote and starts thread to handle data transfer to and from. Not difficult and lots of examples out here. But what is rarely discussed, maybe because it is application specific, is how data is move from the read callback to the object that needs the data. I prefer to keep the functionality compartmentalized. I have done the queue with a event/delegate implementation. That's fine if all the clients data ends up in one place for processing. But what if an object needs to be paired with a comm handler object? Use an interface? Move the business logic into the handler? That defeats the idea that this should be generic enough to be used in other projects. All thoughts and suggestions are welcomed! Thanks, Doug
I am a Traveler of both Time and Space
-
I am in the process of creating a communications server for an application we are building. Pretty standard architecture, multi-threaded, server waits for connection from remote and starts thread to handle data transfer to and from. Not difficult and lots of examples out here. But what is rarely discussed, maybe because it is application specific, is how data is move from the read callback to the object that needs the data. I prefer to keep the functionality compartmentalized. I have done the queue with a event/delegate implementation. That's fine if all the clients data ends up in one place for processing. But what if an object needs to be paired with a comm handler object? Use an interface? Move the business logic into the handler? That defeats the idea that this should be generic enough to be used in other projects. All thoughts and suggestions are welcomed! Thanks, Doug
I am a Traveler of both Time and Space
AeroClassics wrote:
All thoughts and suggestions are welcomed!
Attempting to generalize from one case based on hypotheticals is seldom a good idea. The outcome is often code that is never used, overly complex, more fragile (due to complexity) and can even result in more cost when a real case arrives which is totally incompatible.
-
AeroClassics wrote:
All thoughts and suggestions are welcomed!
Attempting to generalize from one case based on hypotheticals is seldom a good idea. The outcome is often code that is never used, overly complex, more fragile (due to complexity) and can even result in more cost when a real case arrives which is totally incompatible.
JSchell, I see your point. Solving a specific type of problem this way can lead to overly complex code on some ocassions. However, this is really a specific problem that I tried to explain in a way that required the fewest words in an effort to avoid confusion. This problem I have solved a couple of different ways and I am faced with it again. I was not completely happy with my other solutions. Having spent the majority of my career working in the Unix/Linux world these things are done differently. While I have written a lot of desktop code in the MS environment I find that I am trying to apply a Unix mindset to Windows desktop problems. I am not sure this is the best way! So the problem remains. Regardless of where the data stream originates (pipe, TCP/IP etc) waiting for a connection and spinning off a thread to handle that communication channel is the easy part. What I find a bit more difficult to find a decent generic solution for. I am beginning to lean toward using an abstract class or an interface to put the burden on the user of the server object. This is just passing the buck so to speak. Unfortunately I also have to use this object! This lead to the original question. What do most folks do when they need to move data from one object to another? I realize that you can just invoke a method in another object if you have a reference but that, in my personal opinion, is wrong. The server object should not know about the consumer of the data he should just make it available. Typically I toss the data into a queue and invoke an exposed event. But perhaps there is a better way? Doug
I am a Traveler of both Time and Space
-
I am in the process of creating a communications server for an application we are building. Pretty standard architecture, multi-threaded, server waits for connection from remote and starts thread to handle data transfer to and from. Not difficult and lots of examples out here. But what is rarely discussed, maybe because it is application specific, is how data is move from the read callback to the object that needs the data. I prefer to keep the functionality compartmentalized. I have done the queue with a event/delegate implementation. That's fine if all the clients data ends up in one place for processing. But what if an object needs to be paired with a comm handler object? Use an interface? Move the business logic into the handler? That defeats the idea that this should be generic enough to be used in other projects. All thoughts and suggestions are welcomed! Thanks, Doug
I am a Traveler of both Time and Space
AeroClassics wrote:
That's fine if all the clients data ends up in one place for processing. But what if an object needs to be paired with a comm handler object?
Create a dictonary, pair the socket with the object that's about to handle the data :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
JSchell, I see your point. Solving a specific type of problem this way can lead to overly complex code on some ocassions. However, this is really a specific problem that I tried to explain in a way that required the fewest words in an effort to avoid confusion. This problem I have solved a couple of different ways and I am faced with it again. I was not completely happy with my other solutions. Having spent the majority of my career working in the Unix/Linux world these things are done differently. While I have written a lot of desktop code in the MS environment I find that I am trying to apply a Unix mindset to Windows desktop problems. I am not sure this is the best way! So the problem remains. Regardless of where the data stream originates (pipe, TCP/IP etc) waiting for a connection and spinning off a thread to handle that communication channel is the easy part. What I find a bit more difficult to find a decent generic solution for. I am beginning to lean toward using an abstract class or an interface to put the burden on the user of the server object. This is just passing the buck so to speak. Unfortunately I also have to use this object! This lead to the original question. What do most folks do when they need to move data from one object to another? I realize that you can just invoke a method in another object if you have a reference but that, in my personal opinion, is wrong. The server object should not know about the consumer of the data he should just make it available. Typically I toss the data into a queue and invoke an exposed event. But perhaps there is a better way? Doug
I am a Traveler of both Time and Space
AeroClassics wrote:
I realize that you can just invoke a method in another object if you have a reference but that, in my personal opinion, is wrong.
As a general statement - your conclusion is specifically wrong. Basically it condemns OO entirely as well as ignoring the historical concept of RPC and the problems with that when people decided that fine grained objects were the only way to go. (Early adopters of Java RMI experienced the same problem and that includes earlier JEE containers.)
AeroClassics wrote:
But perhaps there is a better way?
If I have a specific architecture or business need for a message queuing system then I use one. I don't use it just as a whim however because of the complexity involved.
-
I am in the process of creating a communications server for an application we are building. Pretty standard architecture, multi-threaded, server waits for connection from remote and starts thread to handle data transfer to and from. Not difficult and lots of examples out here. But what is rarely discussed, maybe because it is application specific, is how data is move from the read callback to the object that needs the data. I prefer to keep the functionality compartmentalized. I have done the queue with a event/delegate implementation. That's fine if all the clients data ends up in one place for processing. But what if an object needs to be paired with a comm handler object? Use an interface? Move the business logic into the handler? That defeats the idea that this should be generic enough to be used in other projects. All thoughts and suggestions are welcomed! Thanks, Doug
I am a Traveler of both Time and Space
Perhaps we are on same quest I just posted this query. Please click here Although I may not have as much UNIX background as you do, I do approach problems in same manner of compartmentalization and what I am essentially attempting to do is implement an UNIX tee.