将抽象部分和它的实现部分分离,使她们都可以独立地变化
-
class Implementor{
-
public:
-
virtual void Operation()=0;
-
};
-
-
class ConcreteImplementorA:public Implementor
-
{
-
public:
-
void Operation()
-
{
-
cout<<\"具体的实现A的方法执行\"<<endl;
-
}
-
};
-
-
class ConcreteImplementorB:public Implementor
-
{
-
public:
-
void Operation()
-
{
-
cout<<\"具体的实现B的方法执行\"<<endl;
-
}
-
};
-
-
class abstraction
-
{
-
protected:
-
Implementor implementor;
-
public:
-
void SetImplementor(Implementor implementor)
-
{
-
this.implementor = implementor;
-
}
-
virtual void Operation()
-
{
-
implementor.Operation;
-
}
-
};
-
-
class RefinedAbstraction:public Abstraction
-
{
-
public:
-
void Operation()
-
{
-
implementor.Operation();
-
}
-
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29012686/viewspace-1128813/
,如需转载,请注明出处,否则将追究法律责任。