Background
I am thinking about designing a (GoF/behavioral) command-pattern interface. I may decide to call this thing ICommand
. I am thinking that I would have some sort of a queue containing a bunch of command-interface objects. I would like to exercise the queue, calling the interface method Execute
for each of the items in this queue as follows...
DequeuedItem.Execute(); // invoke the command-pattern
For every single item in the queue, until exhausting it.
The implementation for the concrete associated with the Execute
may look like...
// concrete implementation of execute
public void Execute()
{
mySerialPort.ReadExisting(); // read data from a serial port
}
From what I understand, using COM ports can be tricky when it comes to who actually owns the port.
Additionally, there are other reasons why I don't just declare the SerialPort
inside of the concrete-implementation. Like... lots and lots of commands will need to use that same port (but not at the same time). So I will need to pass the serial port to the concrete implementing ICommand
. This leads me into my question...
Question
Would an open serial port still function after I pass it to another object?
Even if it would work, are there other implications I need to be conscious of?