Hello all...I am looking for a little help in selecting the correct design pattern for a project I am working on. C++11 is available and this will run on an embedded platform if it matters. I have several devices that will be controlled by relays which will be its own class (maybe a base class, maybe a template class or whatever seems appropriate). I have an enum that I use to track the status of these relays (RELAY_STATUS_OPEN or CLOSED) as well as a return type. The question comes in the handling of the classes I will create for each particular relay connection. Initially I had created another enum that is used for status tracking and as a return type as OPEN and CLOSED don't properly reflect the impact of the relay being open or closed. For instance that RELAY_STATUS_OPEN is actually PUMP_STATUS_OFF in the context of the attached pump. I had begun with a composition approach which creates lots of nearly duplicate code, looked at templates but they seem to be focused on input types (but can be twisted to provide varying return types). I could be looking at this completely wrong so I decided to ask here and see what more experienced people think. To make this more difficult is that I need to be able to dynamically (runtime) create instances of the children classes based on input. I look forward to seeing your thoughts. I can post code of what I have done thus far if it is helpful but I feel as though it isn't the proper approach.
The runtime creation will only happen once and if a change to the system is needed the "configuration" part of the system would be re-run.