当前位置:网站首页>[designmode] Decorator Pattern
[designmode] Decorator Pattern
2022-07-06 00:08:00 【weixin_ forty-three million two hundred and twenty-four thousan】
Basic introduction
Decorator mode : Dynamically attach new functions to objects . In terms of object function expansion , It's more flexible than inheritance , The decorator pattern also embodies the principle of opening and closing (ocp)
The dynamic addition of new functions to objects and ocp principle , In the later application examples, it will be reflected in the form of code , Please pay attention to the experience .
1. Starbucks Coffee order project ( café ):
Types of coffee / Single coffee :Espresso( Espresso )、ShortBlack、LongBlack( Cafe Americano )、Decaf( No cause coffee )
seasoning :Milk、Soy( Soya-bean milk )、Chocolate
When it comes to expanding new types of coffee , It has good expansibility 、 It's easy to change 、 Convenient maintenance
Use OO To calculate the cost of different kinds of coffee : Customers can order a single coffee , You can also have coffee alone + Seasoning mix .
2. programme 1- Solve Starbucks Coffee order project
Poor scheme 1
Class diagram :
3. programme 1- Solve Starbucks Coffee order problem analysis
Drink Is an abstract class , It means drink
des It's a description of coffee , Like the name of the coffee
cost() The way is to calculate the cost ,Drink Class to make an abstract method . 4) Decaf It's a single coffee , Inherit Drink, And implement cost
Espres
边栏推荐
- How much do you know about the bank deposit business that software test engineers must know?
- [designmode] adapter pattern
- 20220703 week race: number of people who know the secret - dynamic rules (problem solution)
- Ffmpeg learning - core module
- Upgrade openssl-1.1.1p for openssl-1.0.2k
- GD32F4xx uIP协议栈移植记录
- 【GYM 102832H】【模板】Combination Lock(二分图博弈)
- MySql——CRUD
- MySQL之函数
- 云呐|固定资产管理系统功能包括哪些?
猜你喜欢
MySql——CRUD
单商户V4.4,初心未变,实力依旧!
NSSA area where OSPF is configured for Huawei equipment
Mathematical model Lotka Volterra
激光slam学习记录
XML configuration file (DTD detailed explanation)
妙才周刊 - 8
How much do you know about the bank deposit business that software test engineers must know?
Senparc.Weixin.Sample.MP源码剖析
总结了 800多个 Kubectl 别名,再也不怕记不住命令了!
随机推荐
认识提取与显示梅尔谱图的小实验(观察不同y_axis和x_axis的区别)
Breadth first search open turntable lock
如何解决ecology9.0执行导入流程流程产生的问题
PADS ROUTER 使用技巧小记
CAS and synchronized knowledge
How much do you know about the bank deposit business that software test engineers must know?
The use of El cascader and the solution of error reporting
总结了 800多个 Kubectl 别名,再也不怕记不住命令了!
XML configuration file (DTD detailed explanation)
wx. Getlocation (object object) application method, latest version
FFmpeg学习——核心模块
FFMPEG关键结构体——AVCodecContext
关于结构体所占内存大小知识
PV static creation and dynamic creation
【SQL】各主流数据库sql拓展语言(T-SQL 、 PL/SQL、PL/PGSQL)
【luogu P3295】萌萌哒(并查集)(倍增)
18. (ArcGIS API for JS) ArcGIS API for JS point collection (sketchviewmodel)
Permission problem: source bash_ profile permission denied
QT a simple word document editor
20220703 周赛:知道秘密的人数-动规(题解)