当前位置:网站首页>[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
边栏推荐
- 云呐|公司固定资产管理系统有哪些?
- 零犀科技携手集智俱乐部:“因果派”论坛成功举办,“因果革命”带来下一代可信AI
- MySql——CRUD
- [gym 102832h] [template] combination lock (bipartite game)
- Convert Chinese into pinyin
- 微信小程序---WXML 模板语法(附带笔记文档)
- 单商户V4.4,初心未变,实力依旧!
- DEJA_ Vu3d - cesium feature set 055 - summary description of map service addresses of domestic and foreign manufacturers
- 【luogu CF487E】Tourists(圆方树)(树链剖分)(线段树)
- 7.5模拟赛总结
猜你喜欢

【二叉搜索树】增删改查功能代码实现

Hardware and interface learning summary

传输层协议------UDP协议

Senparc.Weixin.Sample.MP源码剖析

Key structure of ffmpeg - avformatcontext

剖面测量之提取剖面数据

18. (ArcGIS API for JS) ArcGIS API for JS point collection (sketchviewmodel)

XML配置文件(DTD详细讲解)

Qt QPushButton详解

Detailed explanation of APP functions of door-to-door appointment service
随机推荐
单商户V4.4,初心未变,实力依旧!
Teach you to run uni app with simulator on hbuilderx, conscience teaching!!!
[gym 102832h] [template] combination lock (bipartite game)
Priority queue (heap)
MySQL global lock and table lock
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2
【DesignMode】组合模式(composite mode)
Knowledge about the memory size occupied by the structure
7.5模拟赛总结
Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises
openssl-1.0.2k版本升级openssl-1.1.1p
Senparc.Weixin.Sample.MP源码剖析
【DesignMode】装饰者模式(Decorator pattern)
关于结构体所占内存大小知识
Yunna | what are the main operating processes of the fixed assets management system
Cloudcompare & PCL point cloud randomly adds noise
Breadth first search open turntable lock
The difference of time zone and the time library of go language
FFMPEG关键结构体——AVCodecContext
Key structure of ffmpeg - avformatcontext