当前位置:网站首页>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
边栏推荐
- MH/T 6040航空材料烟密度试验
- 笔试题“将版本号从大到小排列”
- ActiveMQ message component publish subscribe redelivery message redelivery
- Verilog 表达式
- Product manager certification enrollment brochure (NPDP) in July 2022
- Handwriting Redux thunk
- verilog 移位操作符
- JS to obtain basic information about the width and height of an image or Base64
- 微信小程序最新canvas2d手写签名
- ISO16000-9建筑产品和家具中挥发性有机物的测试
猜你喜欢

图片格式-webp

What exactly does Devops mean?

Lffd: a lightweight fast face detector for edge detection

Solutions to ineffective uniapp import components

Unity C # e-learning (12) -- protobuf generation protocol

train_ on_ Batch save the image of the loss function change

手写 redux-thunk

Mysql使用union all统计多张表组合总数,并分别统计各表数量

Remember to customize the top navigation bar of wechat applet

微信小程序分享页面,分享到朋友圈
随机推荐
Working for many years, recalling life -- three years in high school
LFFD:一种用于边缘检测的轻量化快速人脸检测器
Verilog reduction operator
Training kernel switching using GPU
[to.Net] C data model, from Entity Framework core to LINQ
Pat (basic level) practice (Chinese) 1003 I want to pass! (20 points) C language implementation
Open3D 最远点采样(FPS)
图片格式-webp
(转)MySQL: ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
pytorch总结学习系列-数据操作
调试H5页面-weinre及spy-debugger真机调试
keras转tf.keras中VGG19 input_shape
H5 soft keyboard problem
Detecting and counting tiny faces
SSD改进CFENet
Augfpn: amélioration de l'apprentissage des caractéristiques à plusieurs échelles pour la détection des cibles
Did you really make things clear when you were promoted or reported?
Can we trust bounding box annotations for object detection
Training view (issue temporary storage)
微信小程序子组件向页面传值(父子组件间的通信)带源码