Design help with parallel process
- by brazc0re
I am re-factoring some code and an having an issue with retrieving data from two parallel processes.
I have an application that sends packets back and forth via different mediums (ex: RS232, TCP/IP, etc). The jist if of this question is that there are two parallel processes going on.
I hope the picture below displays what is going on better than I can word it:
SetupRS232() class creates a new instance of the SerialPort by:
SerialPort serialPort = new SerialPort();
My question is, what is the best way that the Communicator() class, which sends out the packet via the respective medium, get access to the SerialPort object from the SetupRS232 class? I can do it with a Singleton but have heard that they are generally not the best design to go by.
I am trying to follow SRP but I do feel like I am doing something wrong here. Communicator() will need to go out of it's way to get access to SetupRS232() to get access to the SerialPort class. I actually haven't found a way to even get access to it.
Would designing each medium class, for example, SetupRS232(), SetupTCPIP, as a singleton be the best way to approach this problem?