当前位置:网站首页>[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
边栏推荐
- FFT 学习笔记(自认为详细)
- 第16章 OAuth2AuthorizationRequestRedirectWebFilter源码解析
- Permission problem: source bash_ profile permission denied
- What are the functions of Yunna fixed assets management system?
- Key structure of ffmpeg -- AVCodecContext
- Wechat applet -- wxml template syntax (with notes)
- QT a simple word document editor
- Breadth first search open turntable lock
- Huawei equipment configuration ospf-bgp linkage
- There is no network after configuring the agent by capturing packets with Fiddler mobile phones
猜你喜欢

C reflection and type

Wechat applet -- wxml template syntax (with notes)

选择致敬持续奋斗背后的精神——对话威尔价值观【第四期】

GD32F4xx uIP协议栈移植记录

Teach you to run uni app with simulator on hbuilderx, conscience teaching!!!

Ffmpeg learning - core module

There is no network after configuring the agent by capturing packets with Fiddler mobile phones

What are the functions of Yunna fixed assets management system?

Huawei equipment configuration ospf-bgp linkage

Transport layer protocol ----- UDP protocol
随机推荐
C reflection and type
【SQL】各主流数据库sql拓展语言(T-SQL 、 PL/SQL、PL/PGSQL)
[Luogu p3295] mengmengda (parallel search) (double)
[gym 102832h] [template] combination lock (bipartite game)
【DesignMode】适配器模式(adapter pattern)
Knowledge about the memory size occupied by the structure
Configuring OSPF GR features for Huawei devices
硬件及接口学习总结
【在线聊天】原来微信小程序也能回复Facebook主页消息!
openssl-1.0.2k版本升级openssl-1.1.1p
2022.7.5-----leetcode.729
FFT 学习笔记(自认为详细)
[QT] QT uses qjson to generate JSON files and save them
JS 这次真的可以禁止常量修改了!
Shardingsphere source code analysis
PV静态创建和动态创建
Initialiser votre vecteur & initialisateur avec une liste Introduction à la Liste
Online yaml to CSV tool
Use CAS instead of synchronized
MySql——CRUD