当前位置:网站首页>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
边栏推荐
- 详解关系抽取模型 CasRel
- 421. Maximum XOR value of two numbers in the array
- Go multithread communication, control coordination and main thread shutdown (sync.waitgroup)
- 421. 数组中两个数的最大异或值
- SuperMap iclient for leaflet loads Gauss Kruger projection three-dimensional zonation CGCS2000 geodetic coordinate system WMTs service
- Codeforces round 810 (Div. 2) [competition record]
- Upload pictures to get width and height
- 基址寻址和变址寻址区别
- MVVM architecture encapsulation of kotlin series (kotlin+mvvm)
- Algorithm -- continuous sequence (kotlin)
猜你喜欢

大脑带来的启发:深度神经网络优化中突触整合原理介绍

估值15亿美元的独角兽被爆裁员,又一赛道遇冷?

Photoshop(CC2020)未完

Basic sentence structure of English ----- origin

多态案例-制作饮品

Docker swarm cluster builds highly available MySQL active and standby

Pytoch learning notes (II) the use of neural networks

Brief introduction of reflection mechanism

循环队列(c语言实现)

MySQL's practice of SQL analysis and optimization from the index principle
随机推荐
The.Net webapi uses groupname to group controllers to render the swagger UI
Tdsql-c serverless: help start-ups achieve cost reduction and efficiency increase
Golang port scanning design
Pytorch学习笔记(二)神经网络的使用
404 pages and routing hooks
POM文件详解
.NET WebAPI 使用 GroupName 对 Controller 分组呈现 Swagger UI
Mobile dual finger scaling event (native), e.originalevent.touches
JS download files, filesaver.js export txt and Excel files
Docker container MySQL enables binlog and scheduled backup
JSON data returned by controller
Force deduction ----- the number of words in the string
[collection of topics that C language learners must know 1] consolidate the foundation and steadily improve
[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]
消息的订阅和发布
Pytoch learning notes (II) the use of neural networks
Abstract factory and its improvement examples
Frisbee, 2022 "black red" top stream
JSON data transfer parameters & date type parameter transfer
Unicode file parsing methods and existing problems