当前位置:网站首页>Difference between factory mode and strategy mode
Difference between factory mode and strategy mode
2022-06-29 09:19:00 【amateur12】
Same as :
On the pattern structure , The two are very similar

different :
1. Factory is a creation mode , Its purpose is to create objects , According to the transmission parameters , Create different objects , The method of using an object after it is created
Strategy is a behavioral model , Its function is to let an object choose a behavior among many behaviors
2. Create a focus object , A focus behavior encapsulation
3. The factory parameter is a type , Policy parameter transfer is a new object
summary :
What the factory model can do , Strategic models can do . What the strategic model can do , Factory mode can also do , It just gets troublesome . because , Factory mode is mainly the instantiation object of the returned interface implementation class , Then call the method of the object , The policy pattern object is created when the policy pattern is instantiated , We You can freely splice and rewrite methods in the policy pattern , The factory model is regardless of the splicing of these methods , He only focuses on the final result , Don't pay attention to the process , Only instantiated objects are returned at a time , Then call the object's methods again , The strategic model focuses on the process .
Applicable scenarios :
Factory pattern is a creative design pattern , It takes orders , Create the required instance ; The main solution is the unified distribution of resources , Independent creation of objects , Let the creation of objects have nothing to do with specific customers . Main application in multi database selection , Class library file loading, etc .
The policy mode is used to solve the problem of policy switching and extension , More succinctly, define the policy family , Separately encapsulated , So that they can replace each other , The strategy pattern makes the strategy change independent of the customers who use the strategy .
Add :
Policy mode and Microservices :
The policy pattern is very similar to microservices , For example, we write 3 Interface , Eating is a micro service , Running is a micro service , Dressing is a micro service . The purpose of the strategy model is to connect various methods , Reach a new way , The purpose of microservices is to prevent multiple calls of services , Reduce code coupling , So it seems that the policy mode is similar to the microservice
边栏推荐
- Macros, functions, and inline functions
- 调试H5页面-vConsole
- Highlight in the middle of the navigation bar at the bottom of wechat applet
- Verilog shift operator
- What exactly does Devops mean?
- First electric shock, so you are such a dragon lizard community | dragon lizard developer said that issue 8
- verilog 等价操作符
- Verilog size and +: Using
- 记微信小程序setData动态修改字段名
- 来个小总结吧
猜你喜欢

DevOps到底是什么意思?

Remember to customize the top navigation bar of wechat applet

MT yolov6 training and testing

Abstract classes and interfaces

pytorch总结学习系列-数据操作

深卷积神经网络时代的目标检测研究进展

Uni app gets the route URL of the current page

Cdga | what is the core of digital transformation in the transportation industry?

MT-yolov6训练及测试

MySQL uses union all to count the total number of combinations of multiple tables and the number of tables respectively
随机推荐
微信小程序项目:tab导航栏
Training view (issue temporary storage)
train_ on_ Batch save the image of the loss function change
Working for many years, recalling life -- three years in high school
Figure timers in SOC (I): what timers are there in the system?
微信小程序子组件向页面传值(父子组件间的通信)带源码
来个小总结吧
General multiplier design, verilog code
Let you know today that the passing rate of the PMP Exam is 97%, is it believable
SSD改进CFENet
verilog 等价操作符
jar包和war包
MH/T 6040航空材料烟密度试验
Instance error iopub data rate exceeded
What is hyperfusion? What is the difference with traditional architecture
pytorch总结—自动求梯度
JS to obtain basic information about the width and height of an image or Base64
Mqtt second session -- emqx high availability cluster implementation
Handwritten virtualdom
笔试题“将版本号从大到小排列”