当前位置:网站首页>[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
边栏推荐
- 18. (ArcGIS API for JS) ArcGIS API for JS point collection (sketchviewmodel)
- Tools to improve work efficiency: the idea of SQL batch generation tools
- 18.(arcgis api for js篇)arcgis api for js点采集(SketchViewModel)
- Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4
- 【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)
- 【SQL】各主流数据库sql拓展语言(T-SQL 、 PL/SQL、PL/PGSQL)
- Zhuan: in the future, such an organization can withstand the risks
- 权限问题:source .bash_profile permission denied
- PV static creation and dynamic creation
- FFMPEG关键结构体——AVFormatContext
猜你喜欢
【在线聊天】原来微信小程序也能回复Facebook主页消息!
Single merchant v4.4 has the same original intention and strength!
Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
如何解决ecology9.0执行导入流程流程产生的问题
Key structure of ffmpeg - avframe
【DesignMode】装饰者模式(Decorator pattern)
硬件及接口学习总结
Problems encountered in the database
Hardware and interface learning summary
Use mapper: --- tkmapper
随机推荐
【EF Core】EF Core与C# 数据类型映射关系
FFmpeg学习——核心模块
关于slmgr命令的那些事
QT -- thread
Problem solving win10 quickly open ipynb file
C reflection and type
FFT learning notes (I think it is detailed)
【DesignMode】组合模式(composite mode)
JS 这次真的可以禁止常量修改了!
Which side projects can be achieved? Is it difficult for we media to earn more than 10000 a month?
Qt QPushButton详解
[designmode] composite mode
[Luogu p3295] mengmengda (parallel search) (double)
Breadth first search open turntable lock
单商户V4.4,初心未变,实力依旧!
Open source CRM customer relationship system management system source code, free sharing
[gym 102832h] [template] combination lock (bipartite game)
Transport layer protocol ----- UDP protocol
云呐|固定资产管理系统主要操作流程有哪些
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2