当前位置:网站首页>[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
边栏推荐
- 2022.7.5-----leetcode.729
- Add noise randomly to open3d point cloud
- DEJA_VU3D - Cesium功能集 之 055-国内外各厂商地图服务地址汇总说明
- Qt 一个简单的word文档编辑器
- MySQL之函数
- CAS and synchronized knowledge
- JS can really prohibit constant modification this time!
- 【luogu P3295】萌萌哒(并查集)(倍增)
- Make a short video clip number of we media film and television. Where can I download the material?
- GD32F4xx uIP协议栈移植记录
猜你喜欢

云呐|固定资产管理系统主要操作流程有哪些

【DesignMode】组合模式(composite mode)

Huawei equipment configuration ospf-bgp linkage

Determinant learning notes (I)

Open source CRM customer relationship system management system source code, free sharing

XML configuration file (DTD detailed explanation)

20220703 周赛:知道秘密的人数-动规(题解)

Gd32f4xx UIP protocol stack migration record

Breadth first search open turntable lock

wx.getLocation(Object object)申请方法,最新版
随机推荐
"14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications
7.5 decorator
关于结构体所占内存大小知识
There is no network after configuring the agent by capturing packets with Fiddler mobile phones
Tips for using pads router
QT QPushButton details
Huawei equipment configuration ospf-bgp linkage
Key structure of ffmpeg - avformatcontext
XML configuration file (DTD detailed explanation)
Wechat applet -- wxml template syntax (with notes)
Open source CRM customer relationship system management system source code, free sharing
Key structure of ffmpeg - avframe
USB Interface USB protocol
JVM details
Priority queue (heap)
How to get all the values stored in localstorage
妙才周刊 - 8
云呐|固定资产管理系统主要操作流程有哪些
【DesignMode】装饰者模式(Decorator pattern)
Which side projects can be achieved? Is it difficult for we media to earn more than 10000 a month?