当前位置:网站首页>[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
边栏推荐
- After summarizing more than 800 kubectl aliases, I'm no longer afraid that I can't remember commands!
- 2022.7.5-----leetcode.729
- 教你在HbuilderX上使用模拟器运行uni-app,良心教学!!!
- 跟着CTF-wiki学pwn——ret2libc1
- The use of El cascader and the solution of error reporting
- 【DesignMode】装饰者模式(Decorator pattern)
- 云呐|公司固定资产管理系统有哪些?
- 时区的区别及go语言的time库
- [Luogu cf487e] tours (square tree) (tree chain dissection) (line segment tree)
- 软件测试工程师必会的银行存款业务,你了解多少?
猜你喜欢

硬件及接口学习总结

如何解决ecology9.0执行导入流程流程产生的问题

The difference of time zone and the time library of go language

18.(arcgis api for js篇)arcgis api for js点采集(SketchViewModel)

Laser slam learning record

What if the C disk is not enough? Let's see how I can clean up 25g of temp disk space after I haven't redone the system for 4 years?

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

MySql——CRUD

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

Configuring OSPF load sharing for Huawei devices
随机推荐
[noi simulation] Anaid's tree (Mobius inversion, exponential generating function, Ehrlich sieve, virtual tree)
QT -- thread
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
Asynchronous task Whenall timeout - Async task WhenAll with timeout
Zhuan: in the future, such an organization can withstand the risks
Laser slam learning record
[Luogu p3295] mengmengda (parallel search) (double)
Single merchant v4.4 has the same original intention and strength!
妙才周刊 - 8
云呐|固定资产管理系统主要操作流程有哪些
时区的区别及go语言的time库
MySQL functions
激光slam学习记录
多普勒效應(多普勒頻移)
Choose to pay tribute to the spirit behind continuous struggle -- Dialogue will values [Issue 4]
Mysql - CRUD
wx.getLocation(Object object)申请方法,最新版
亲测可用fiddler手机抓包配置代理后没有网络
MySql——CRUD
【DesignMode】组合模式(composite mode)