当前位置:网站首页>[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
边栏推荐
- PV static creation and dynamic creation
- 【EF Core】EF Core与C# 数据类型映射关系
- 云呐|固定资产管理系统功能包括哪些?
- FFMPEG关键结构体——AVFrame
- [SQL] SQL expansion languages of mainstream databases (T-SQL, pl/sql, pl/pgsql)
- Mysql - CRUD
- What is information security? What is included? What is the difference with network security?
- Configuring OSPF load sharing for Huawei devices
- JS can really prohibit constant modification this time!
- Tools to improve work efficiency: the idea of SQL batch generation tools
猜你喜欢
How to rotate the synchronized / refreshed icon (EL icon refresh)
数据库遇到的问题
用列錶初始化你的vector&&initializer_list簡介
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?
20220703 周赛:知道秘密的人数-动规(题解)
JVM details
[noi simulation] Anaid's tree (Mobius inversion, exponential generating function, Ehrlich sieve, virtual tree)
Priority queue (heap)
PV静态创建和动态创建
单商户V4.4,初心未变,实力依旧!
随机推荐
Redis high availability - master-slave replication, sentinel mode, cluster
用列表初始化你的vector&&initializer_list简介
【luogu P3295】萌萌哒(并查集)(倍增)
用列錶初始化你的vector&&initializer_list簡介
7.5模拟赛总结
My colleagues quietly told me that flying Book notification can still play like this
Qt QPushButton详解
[SQL] SQL expansion languages of mainstream databases (T-SQL, pl/sql, pl/pgsql)
Huawei equipment configuration ospf-bgp linkage
Key structure of ffmpeg -- AVCodecContext
18. (ArcGIS API for JS) ArcGIS API for JS point collection (sketchviewmodel)
零犀科技携手集智俱乐部:“因果派”论坛成功举办,“因果革命”带来下一代可信AI
Initialiser votre vecteur & initialisateur avec une liste Introduction à la Liste
Huawei equipment is configured with OSPF and BFD linkage
妙才周刊 - 8
Senparc.Weixin.Sample.MP源码剖析
微信小程序---WXML 模板语法(附带笔记文档)
Permission problem: source bash_ profile permission denied
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?
Upgrade openssl-1.1.1p for openssl-1.0.2k