赞
踩
- #include "iostream"
- #include "string"
- #include <vector>
- #include <mutex>
-
- using namespace std;
-
- class Implementor
- {
- public:
- virtual void OperationImpl()=0;
- virtual ~Implementor(){}
- };
-
- class ConcreteImplementorA:public Implementor
- {
- public:
- void OperationImpl()
- {
- cout << "ConcreteImplementorA operationImpl" << endl;
- };
-
- };
-
- class ConcreteImplementorB :public Implementor
- {
- public:
- void OperationImpl()
- {
- cout << "ConcreteImplementorB operationImpl" << endl;
- };
-
- };
-
- class Abstraction
- {
- public:
- virtual ~Abstraction(){};
- Abstraction(Implementor*implementor):implementor_(implementor){};
- virtual void operation()
- {
- implementor_->OperationImpl();
- }
-
- private:
- Implementor *implementor_;
- };
-
- class RefinedAbstraction :public Abstraction
- {
- public:
- RefinedAbstraction(Implementor*implementor):Abstraction(implementor){}
- void operation()
- {
- cout<<"RefinedAbstraction operation"<<endl;
- Abstraction::operation();
- }
-
- };
-
- int main()
- {
- Implementor*implementorA=new ConcreteImplementorA();
- Abstraction*abstractionA=new RefinedAbstraction(implementorA);
- abstractionA->operation();
-
- delete implementorA;
- delete abstractionA;
-
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。