Question

I am trying design a generic hardware facade interface for different camera types. below is my incomplete generic interface for camera devices

template <class Data,class Configuration>
class CameraDevice : public Device {
public:
    CameraDevice(DeviceModel model);
    virtual void startStreaming(std::function<void(Data &data)> callback) = 0;
    virtual void stopStreaming() = 0;
    virtual void setConfiguration(const Configuration configuration) = 0;
    virtual ~CameraDevice();
}; 

Data = the type of data the device generates. this varies between different hardware.

Configuration = device configuration class which also varies between different hardware

I have created a concrete sub-class with defined Data & Configuration types and provided the implementations for the virtual classes.

Now, my question is how can I take this CameraDevice* interface and use it in my generic hardware facade/proxy interface in such a way that its client won't have to change when I swap cameras. This is a design question and I'm looking for some ideas/examples. perhaps I need to think in a different direction ?

Thanks in advance

Was it helpful?

Solution

By adding the camera-specific classes Data and Configuration as template parameters to your interface, it is no longer a really generic, camera agnostic, interface. The clients will have to know about the Data and Configuration classes that the camera supports and they can only switch between camera's that use the exact same Data and Configuration classes.

If you want to be able to swap between different camera's that use different Data and/or Configuration classes without having to recompile the client, then the interface used by the client must be completely agnostic of those differences. That means that a generic CameraDevice interface must also use a generic Data interface and a generic Configuration interface.

Licensed under: CC-BY-SA with attribution
scroll top