当前位置:网站首页>[designmode] template method pattern
[designmode] template method pattern
2022-07-07 16:36:00 【weixin_ forty-three million two hundred and twenty-four thousan】
Basic introduction
Template method pattern (Template Method Pattern), Also called template mode (Template Pattern),z In an abstract class, the template that defines the method to execute it is exposed . Its subclass can override method implementation as needed , But the call will take place in the way defined in the abstract class .
In short , Template method pattern Defines the skeleton of an algorithm in an operation , Instead, defer some steps to subclasses , So that the subclass can not change the structure of an algorithm , You can redefine some specific steps of the algorithm
This type of design pattern belongs to behavioral pattern .
1. Problems in soybean milk production
Write procedures for making soybean milk , The explanation is as follows :
The process of making soybean milk Material selection —> Add ingredients —> soak —> Break it in the soymilk machine
By adding different ingredients , You can make soymilk with different flavors
Material selection 、 Soaking and smashing in a soymilk machine are the same for every flavor of soymilk
Please use Template method pattern complete ( explain : Because the template method pattern , Relatively simple , It's easy to come up with this plan , So use it directly , No longer use the traditional scheme to lead out the template method pattern )
2. Basic introduction to template method pattern
Basic introduction
Template method pattern (Template Method Pattern), Also called template mode (Template Pattern),z In an abstract class, the template that defines the method to execute it is exposed . Its subclass can override method implementation as needed , But the call will take place in the way defined in the abstract class .
In short , Template method pattern Defines the skeleton of an algorithm in an operation , Instead, defer some steps to subclasses , So that subclasses can not
边栏推荐
- What is the difference between IP address and physical address
- Inner monologue of accidental promotion
- null == undefined
- The differences between exit, exit (0), exit (1), exit ('0 '), exit ('1'), die and return in PHP
- 【医学分割】attention-unet
- Laravel5.1 Routing - routing packets
- Prediction - Grey Prediction
- php 自带过滤和转义函数
- Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
- laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
猜你喜欢
随机推荐
Geoserver2.18 series (5): connect to SQLSERVER database
PHP中exit,exit(0),exit(1),exit(‘0’),exit(‘1’),die,return的区别
Personal notes of graphics (4)
2022 the 4th China (Jinan) International Smart elderly care industry exhibition, Shandong old age Expo
Pycharm terminal enables virtual environment
torch. Numel action
Imitate the choice of enterprise wechat conference room
Performance comparison of tidb for PostgreSQL and yugabytedb on sysbench
平衡二叉树(AVL)
What about the pointer in neural network C language
Markdown formula editing tutorial
Three. JS series (3): porting shaders in shadertoy
Personal notes of graphics (3)
面试题 01.02. 判定是否互为字符重排-辅助数组算法
OpenGL personal notes
What is the difference between IP address and physical address
Usage of config in laravel
二叉搜索树(基操篇)
How to query the data of a certain day, a certain month, and a certain year in MySQL
预测——灰色预测