简体   繁体   中英

Existing class from library implements interface

I am developing a software which needs to detect different kinds of tracking codes (barcode, qr-code, RFID, etc). I have made an interface TrackingIdentifier which will be implemented by BarcodeIdentifier , QRCodeIdentifier , RFIDIdentifier , etc. For barcode and qrcode, the input to the detection algorithm will be cv::Mat &image. But for RFID it will be something else. The code will be something like this :

class TrackingIdentifier{

public:
virtual std::string getTrackingCode(ITrackingInfoHolder *holder) = 0;
};

Can the existing cv::Mat implement this ITrackingInfoHolder ?

You could use the Adapter Pattern .

struct MatInfo : ITrackingInfoHolder {
    info getInfo() override {
        return mat....();  // delegate to cv::Mat implementation
    }

private:
    cv::Mat mat;
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM