当前位置:网站首页>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
边栏推荐
- Verilog splicing operation symbol
- 微信小程序项目:微信小程序页面布局
- YOLO Nano:一种高度紧凑的只看一次的卷积神经网络用于目标检测
- 超融合架构和传统架构有什么区别?
- YOLACT实时实例分割
- Professional structure record
- First electric shock, so you are such a dragon lizard community | dragon lizard developer said that issue 8
- Uni app gets the route URL of the current page
- PointNet/Pointnet++训练及测试
- promise方法的简单使用
猜你喜欢
随机推荐
UE4 去掉材质中Mask透明白边
Verilog equivalent operator
Detecting and counting tiny faces
Member inner class, static inner class, local inner class
Detailed version of two-stage target detection principle
记微信小程序分享代码片段
微信小程序判断url的文件格式
调试H5页面-vConsole
SSD improvements cfenet
Pat (basic level) practice (Chinese) 1003 I want to pass! (20 points) C language implementation
实例报错IOPub data rate exceeded
微信小程序底部导航栏中间突出
Keras to tf Vgg19 input in keras_ shape
AugFPN:改進多尺度特征學習用於目標檢測
MYSQL行转列例子
promise方法的简单使用
(转)MySQL: ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
在 golang 中是如何对 epoll 进行封装的?
Enrollment brochure for system integration project management engineer certification in July 2022
Product manager certification enrollment brochure (NPDP) in July 2022








