当前位置:网站首页>【DesignMode】模板方法模式(Template method pattern)
【DesignMode】模板方法模式(Template method pattern)
2022-07-07 14:16:00 【weixin_43224306】
基本介绍
模板方法模式(Template Method Pattern),又叫模板模式(Template Pattern),z 在一个抽象类公开定义了执行它的方法的模板。它的子类可以按需要重写方法实现,但调用将以抽象类中定义的方式进行。
简单说,模板方法模式 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中,使得子类可以不改变一个算法的结构,就可以重定义该算法的某些特定步骤
这种类型的设计模式属于行为型模式。
1. 豆浆制作问题
编写制作豆浆的程序,说明如下:
制作豆浆的流程 选材—>添加配料—>浸泡—>放到豆浆机打碎
通过添加不同的配料,可以制作出不同口味的豆浆
选材、浸泡和放到豆浆机打碎这几个步骤对于制作每种口味的豆浆都是一样的
请使用 模板方法模式 完成 (说明:因为模板方法模式,比较简单,很容易就想到这个方案,因此就直接使用,不再使用传统的方案来引出模板方法模式 )
2. 模板方法模式基本介绍
基本介绍
模板方法模式(Template Method Pattern),又叫模板模式(Template Pattern),z 在一个抽象类公开定义了执行它的方法的模板。它的子类可以按需要重写方法实现,但调用将以抽象类中定义的方式进行。
简单说,模板方法模式 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中,使得子类可以不
边栏推荐
- SPI master RX time out interrupt
- Spark Tuning (III): persistence reduces secondary queries
- 【知识小结】PHP使用svn笔记总结
- thinkphp3.2.3中设置路由,优化url
- Multiplication in pytorch: mul (), multiply (), matmul (), mm (), MV (), dot ()
- 一个普通人除了去工厂上班赚钱,还能干什么工作?
- What else can an ordinary person do besides working in a factory to make money?
- Xingruige database was shortlisted as the "typical solution for information technology application and innovation in Fujian Province in 2021"
- 平衡二叉树(AVL)
- Xcode Revoke certificate
猜你喜欢
Prediction - Grey Prediction
Power of leetcode-231-2
1亿单身男女“在线相亲”,撑起130亿IPO
Enterprise log analysis system elk
95. (cesium chapter) cesium dynamic monomer-3d building (building)
Logback日志框架第三方jar包 免费获取
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
The difference and working principle between compiler and interpreter
Pycharm terminal enables virtual environment
Description of vs common shortcut keys
随机推荐
torch.numel作用
Vs tool word highlight with margin
three. JS create cool snow effect
47_Opencv中的轮廓查找 cv::findContours()
IP地址和物理地址有什么区别
分步式监控平台zabbix
Spark Tuning (III): persistence reduces secondary queries
Unity3d click events added to 3D objects in the scene
Laravel5.1 Routing - routing packets
thinkphp3.2.3中设置路由,优化url
Bidding announcement: Fujian Rural Credit Union database audit system procurement project (re bidding)
asyncio 概念和用法
Particle effect for ugui
Power of leetcode-231-2
Xcode Revoke certificate
AutoLISP series (3): function function 3
laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
Excessive dependence on subsidies, difficult collection of key customers, and how strong is the potential to reach the dream of "the first share of domestic databases"?
PHP has its own filtering and escape functions