#include<iostream>
#include<cstdio>
using namespace std;
class FlyBehavior{
public:
FlyBehavior(){};
~FlyBehavior(){}
virtual void fly()=0;
};
class FlyWithWings :public FlyBehavior{
public:
FlyWithWings(){}
~FlyWithWings(){}
void fly()
{
cout<<"I'm flying"<<endl;
}
};
class FlyNoWay :public FlyBehavior{
public:
FlyNoWay(){}
~FlyNoWay(){}
void fly()
{
cout<<"I can't fly"<<endl;
}
};
class QuackBehavior{
public:
QuackBehavior(){};
~QuackBehavior(){}
virtual void quack()=0;
};
class Quack :public QuackBehavior{
public:
Quack(){}
~Quack(){}
void quack(){
cout<<"呱呱叫"<<endl;
}
};
class Squeak :public QuackBehavior{
public:
Squeak(){}
~Squeak(){}
void quack(){
cout<<"吱吱叫"<<endl;
}
};
class MuteQua
设计模式入门之鸭子问题
最新推荐文章于 2022-08-15 17:44:39 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)