当前位置:网站首页>【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 在一个抽象类公开定义了执行它的方法的模板。它的子类可以按需要重写方法实现,但调用将以抽象类中定义的方式进行。
简单说,模板方法模式 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中,使得子类可以不
边栏推荐
- Strengthen real-time data management, and the British software helps the security construction of the medical insurance platform
- Bidding announcement: Fujian Rural Credit Union database audit system procurement project (re bidding)
- 应用程序和matlab的通信方式
- 3000 words speak through HTTP cache
- Set the route and optimize the URL in thinkphp3.2.3
- SPI master RX time out interrupt
- What else can an ordinary person do besides working in a factory to make money?
- How to implement backspace in shell
- Unity drawing plug-in = = [support the update of the original atlas]
- How does laravel run composer dump autoload without emptying the classmap mapping relationship?
猜你喜欢

AutoLISP series (1): function function 1

Imitate the choice of enterprise wechat conference room

Balanced binary tree (AVL)
![Application example of infinite list [uigridview]](/img/11/3be1c63680e6de8f068e79690ecf12.jpg)
Application example of infinite list [uigridview]

Step by step monitoring platform ZABBIX

Logback日志框架第三方jar包 免费获取

Mysql database basic operation DQL basic query

What are compiled languages and interpreted languages?

企业级日志分析系统ELK

The difference and working principle between compiler and interpreter
随机推荐
asyncio 概念和用法
iptables只允许指定ip地址访问指定端口
How to query the data of a certain day, a certain month, and a certain year in MySQL
Logback logging framework third-party jar package is available for free
Performance measure of classification model
分类模型评价标准(performance measure)
Asyncio concept and usage
PHP中exit,exit(0),exit(1),exit(‘0’),exit(‘1’),die,return的区别
U3D_ Infinite Bessel curve
MySQL中, 如何查询某一天, 某一月, 某一年的数据
Set the route and optimize the URL in thinkphp3.2.3
Laravel 中config的用法
MySQL数据库基本操作-DQL-基本查询
Description of vs common shortcut keys
Performance comparison of tidb for PostgreSQL and yugabytedb on sysbench
PHP realizes wechat applet face recognition and face brushing login function
Leetcode-136- number that appears only once (solve with XOR)
Mysql database basic operation DQL basic query
Imitate the choice of enterprise wechat conference room
Statistical learning method -- perceptron