Well, I’ve been thinking about a design solution for the past few days, and since I still can’t support each other, I thought maybe someone has an idea.
The situation is this: I have a couple of different classes of interface abstracting several communication devices. Since these devices differ in nature, they also differ in interface and, therefore, are not connected to each other. Let's call them IFooDevice and IBarDevice . Over time, additional types of devices may be added. Language - C ++.
Since other components (called clients from now on) can use one or more of these devices, I decided to provide a DeviceManager class to handle access to all available devices at runtime. Since the number of types of devices can increase, I would like to treat all devices equally (from the point of view of managers). However, clients will request a specific type of device (or device based on some properties).
I thought of two possible solutions:
The first will be some kind of hierarchy of intervention. All devices will subclass the common IDevice interface , which will provide the (virtual) methods needed to manage and query the device (e.g. getProperties (), hasProperties (), ...). DeviceManager has a collection of pointers to an IDevice , and at some point a throw from Base to Derived will be required - either using the template method in the manager, or after a request on the client side.
, , . , : IManagedDevice , , IFooDevice. , "" . IManagedDevice. - (, IManagedDevice IFooDevice), , .
? ? - ?
Edit:
"" . , , , () . , . "" , , . , , ( , ), . , , .