#include <iostream>
using namespace std;
class AbstractDrinking
{
public:
virtual void Boil() = 0;
virtual void Brew() = 0;
virtual void PourInCup() = 0;
virtual void PutSomething() = 0;
void MakeDrink()
{
Boil();
Brew();
PourInCup();
PutSomething();
}
};
class coffee :public AbstractDrinking
{
public:
virtual void Boil()
{
cout << "煮开水" << endl;
}
virtual void Brew()
{
cout << "加入咖啡粉" << endl;
}
virtual void PourInCup()
{
cout << "倒入咖啡杯中" << endl;
}
virtual void PutSomething()
{
cout << "加一包糖" << endl;
}
void MakeDrink()
{
Boil();
Brew();
PourInCup();
PutSomething();
}
};
class tea : public AbstractDrinking
{
public:
virtual void Boil()
{
cout << "煮开水" << endl;
}
virtual void Brew()
{
cout << "加入茶叶" << endl;
}
virtual void PourInCup()
{
cout << "倒入茶杯中" << endl;
}
virtual void PutSomething()
{
cout << "加柠檬" << endl;
}
void MakeDrink()
{
Boil();
Brew();
PourInCup();
PutSomething();
}
};
void test1()
{
AbstractDrinking* p = new coffee;
p->MakeDrink();
delete p;
p = new tea;
p->MakeDrink();
delete p;
}
void doWork(AbstractDrinking* p)
{
p->MakeDrink();
delete p;
}
void test2()
{
doWork(new coffee);
doWork(new tea);
}
int main()
{
test2();
return 0;
}