c++开发模式桥接模式

将抽象部分与它的实现部分分离,使它们都可以独立地变化。它是一种对象结构型模式,又称为柄体(Handle and Body)模式或接口(Interface)模式。

#include 
using namespace std;

// Abstraction

class Abstraction {
public:
    virtual void Operation() = 0;
    virtual ~Abstraction() { }
protected:
    Abstraction() { }
};

// AbstractionImp

class AbstractionImp :public Abstraction {
public:
    virtual void Operation() = 0;
    virtual ~AbstractionImp() { }
protected:
    AbstractionImp() { }
};

class ConcreteAbstractionImp :public AbstractionImp {
public:
    void Operation() {
        cout << "ConcreteAbstractionImp Operation..." << endl;
    }
};

class RefinedAbstraction :public Abstraction {
public:
    RefinedAbstraction(AbstractionImp *imp) {
        _imp = imp;
    }
    void Operation() {
        _imp->Operation();
    }
private:
    AbstractionImp *_imp;
};





int main() {

    AbstractionImp *imp = new ConcreteAbstractionImp();

    Abstraction *abs = new RefinedAbstraction(imp);

    abs->Operation();

    delete imp;
    delete abs;

    return 0;
}

你可能感兴趣的:(c++,桥接模式,算法)