I have a situation in Java where I have an external device that I want to communicate via serial I/O. I know how to do this, but I'm now in a refactoring mode to make sure I've got a maintainable software package, & was looking for advice on what to do / not to do at a high level (specific questions below)
Conceptually, let's say I have a low-level DeviceIOChannel interface with several methods (getInputStream, getOutputStream, and some other ones for controlling connection / disconnection detection, etc.), implemented by one or more classes that handle the I/O for various data link types (RS232, TCPIP, etc). Some of my software, let's call it a Device class, is devoted to managing the I/O (parsing the input, constructing output, managing low-level state machines), but without knowing the details of how DeviceIOChannel does its thing (so I can use it with RS232 or TCPIP without having to change the Device class). So I'll probably pass in DeviceIOChannel as a parameter to Device's constructor. I also would like to expose some sort of data model to the outside world.
- Does my partitioning of DeviceIOChannel/Devicesound right?
- Deviceneeds to be doing some things actively on a worker thread. What's the best way to set this up? Should I have it create and manage its own- Threador- ScheduledExecutorService? Or should I pass in a- ScheduledExecutorServiceas a construction parameter?
- any thoughts (links to good articles on the web would be ideal!) about how to whether or not the Deviceclass should have astartup()method distinct from construction? (doing all the initialization in construction makes me nervous... seems like class instance construction should be quick, and then lengthy stuff should be reserved for an init or startup phase that comes later.)
- What about whether to have a Deviceclass with a pair of shutdown / restart methods, vs. no shutdown + requiring a newDeviceinstance to be created?
- I'm still new to MVC architecture: would it make sense to create a DeviceDataModelinterface thatDeviceimplements, or should I have some separate classDeviceDataModelthat somehow has two-way communication with theDeviceclass?