当前位置:网站首页>Polymorphic case - making drinks
Polymorphic case - making drinks
2022-07-26 13:50:00 【The right path in the world is vicissitudes 80】
#if 1
#include<iostream>
using namespace std;
class AbstractDrinking
{
public:
// Boil the water
virtual void Boil() = 0;
// Brewing
virtual void Brew() = 0;
// Pour it into a cup
virtual void PoutInCup() = 0;
// Add accessories
virtual void PutSomething() = 0;
// Making drinks
void makeDrink()
{
Boil();
Brew();
PoutInCup();
PutSomething();
}
};
class Coffee :public AbstractDrinking
{
public:
// Boil the water
virtual void Boil()
{
cout << " Boil Nongfu mountain spring " << endl;
}
// Brewing
virtual void Brew()
{
cout << " Making coffee " << endl;
}
// Pour it into a cup
virtual void PoutInCup()
{
cout << " Pour it into a cup " << endl;
}
// Add accessories
virtual void PutSomething()
{
cout << " Add sugar and milk " << endl;
}
};
// Making tea
class Tea :public AbstractDrinking {
public:
// Boil the water
virtual void Boil()
{
cout << " Boil mineral water " << endl;
}
// Brewing
virtual void Brew()
{
cout << " Brew tea " << endl;
}
// Pour it into a cup
virtual void PoutInCup()
{
cout << " Pour it into a cup " << endl;
}
// Add accessories
virtual void PutSomething()
{
cout << " Add wolfberry " << endl;
}
};
// Making functions
void doWork(AbstractDrinking* abs) //AbstractDrinking* abs = new coffee;
{
abs->makeDrink();
delete abs;// Release
}
void test01()
{
// Making coffee
doWork(new Coffee);
cout << "------------" << endl;
doWork(new Tea);
}
int main()
{
test01();
system("pause");
return 0;
}
#endif
边栏推荐
- Segmentation fault (core dumped)
- Detailed explanation of factory mode
- Unicorn, valued at $1.5 billion, was suddenly laid off, and another track was cold?
- Parent class reference to child class (parent class reference points to child class object)
- Familiarize you with the "phone book" of cloud network: DNS
- The picture moves horizontally with the phone - gyroscope. 360 degree setting conditions
- Propagation of transactions
- 力扣------字符串中的单词数
- 带你熟悉云网络的“电话簿”:DNS
- 白帽子揭秘:互联网千亿黑产吓退马斯克
猜你喜欢

JSON data transfer parameters & date type parameter transfer

We were tossed all night by a Kong performance bug

【Oauth2】五、OAuth2LoginAuthenticationFilter

MVVM architecture encapsulation of kotlin series (kotlin+mvvm)

Algorithm -- continuous sequence (kotlin)

Jenkins 中 shell 脚本执行失败却不自行退出

循环队列(c语言实现)

大小端模式

The difference between V-model and.Sync modifier

MySql的DDL和DML和DQL的基本语法
随机推荐
ROS2学习(1)ROS2简述
Pytorch学习笔记(一)安装与常用函数的使用
Convert the array in JSON file to struct
Basic sentence structure of English ----- origin
"Intermediate and advanced test questions": what is the implementation principle of mvcc?
Pytoch learning notes (I) installation and use of common functions
Intercept the coordinate points (four point coordinates of the face frame) face image from the marked XML file and save it in the specified folder
Using the geoprocessor tool
Jenkins 中 shell 脚本执行失败却不自行退出
WPS凭什么拒绝广告?
时间复杂度和空间复杂度
【Oauth2】五、OAuth2LoginAuthenticationFilter
Time complexity analysis of bubble sorting
Force deduction ----- the number of words in the string
MySql的DDL和DML和DQL的基本语法
Docker integrates the redis sentinel mode (one master, two slave and three sentinels)
从标注好的xml文件中截取坐标点(人脸框四个点坐标)人脸图像并保存在指定文件夹
算法--连续数列(Kotlin)
Tianyi cloud web application firewall (edge cloud version) supports the detection and interception of Apache spark shell command injection vulnerabilities
Latest battle report: Ten certifications and five best practices