class CameraOpt{
public:
QLabel label;
int type;//1 DH;2、HIK;3、OpenCV初始化时根据这个字段来区分这个类是那个子类的
Param param;
public:
bool virtual openVideo();
bool virtual closeVideo();
bool virtual getVideoStatus();
protect:
bool virtual initParam();
}
class CameraOptOpenCV : public CameraOpt{
public:
VideoCapture cap;
Mat mat;
public:
bool openVideo() override;
bool closeVideo() override;
bool getVideoStatus() override;
protected:
bool initParam() override;
}
class CameraOptSDK : public CameraOpt{
public:
bool virtual ratate();//旋转
bool virtual ptz();
bool virtual wiper();//雨刷
private:
bool virtual login();
bool virtual logout();
}
class CameraOptDH : public CameraOptSDK{
public:
bool openVideo() override;
bool closeVideo() override;
bool getVideoStatus() override;
bool ratate() override;
bool ptz() override;
bool wiper() override;
protected:
bool initParam() override;
private:
bool login() override;
bool logout() override;
LONG port = -1;
}
class CameraOptHIK : public CameraOptSDK{
public:
bool openVideo() override;
bool closeVideo() override;
bool getVideoStatus() override;
bool ratate() override;
bool ptz() override;
bool wiper() override;
protected:
bool initParam() override;
private:
bool login() override;
bool logout() override;
friend void CALLBACK realDataCallback(LLONG lRealHandle);
}
我想通过 CameraOpt的属性 flag ,将其动态类型转换为各个子类,完成对子类方法的调用。
即在项目中有多个CameraOpt指针,当需要使用时,对其flag对象赋值,然后动态类型转换为对应的子类,完成那么多方法操作……
怎么便捷地把CameraOpt转换为各子类?
设计模式 之 策略模式、状态模式
大致看了,策略模式,他们需要继承同一个接口,但是这里面接最下面的三个类里面OpenCV和其他的比较,方法数量少