当前位置:网站首页>[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
边栏推荐
- 选择致敬持续奋斗背后的精神——对话威尔价值观【第四期】
- [QT] QT uses qjson to generate JSON files and save them
- [Luogu cf487e] tours (square tree) (tree chain dissection) (line segment tree)
- 软件测试工程师必会的银行存款业务,你了解多少?
- PV静态创建和动态创建
- 7.5 decorator
- Breadth first search open turntable lock
- XML configuration file (DTD detailed explanation)
- FFMPEG关键结构体——AVFrame
- MySql——CRUD
猜你喜欢
Doppler effect (Doppler shift)
云呐|固定资产管理系统主要操作流程有哪些
Breadth first search open turntable lock
Ffmpeg learning - core module
【DesignMode】装饰者模式(Decorator pattern)
Hudi of data Lake (2): Hudi compilation
How much do you know about the bank deposit business that software test engineers must know?
亲测可用fiddler手机抓包配置代理后没有网络
openssl-1.0.2k版本升级openssl-1.1.1p
Open source CRM customer relationship system management system source code, free sharing
随机推荐
【luogu CF487E】Tourists(圆方树)(树链剖分)(线段树)
How to rotate the synchronized / refreshed icon (EL icon refresh)
wx. Getlocation (object object) application method, latest version
20220703 week race: number of people who know the secret - dynamic rules (problem solution)
Open source CRM customer relationship system management system source code, free sharing
QT--线程
认识提取与显示梅尔谱图的小实验(观察不同y_axis和x_axis的区别)
微信小程序---WXML 模板语法(附带笔记文档)
Hardware and interface learning summary
多普勒效应(多普勒频移)
选择致敬持续奋斗背后的精神——对话威尔价值观【第四期】
关于结构体所占内存大小知识
如何解决ecology9.0执行导入流程流程产生的问题
【DesignMode】装饰者模式(Decorator pattern)
Qt 一个简单的word文档编辑器
零犀科技携手集智俱乐部:“因果派”论坛成功举办,“因果革命”带来下一代可信AI
Laser slam learning record
MySql——CRUD
[online chat] the original wechat applet can also reply to Facebook homepage messages!
Gd32f4xx UIP protocol stack migration record