当前位置:网站首页>A little consideration of strategic mode
A little consideration of strategic mode
2022-07-25 06:27:00 【Little wolf】
Speaking of strategic mode , When talking about my thinking about its use , First look at his existing axioms :
Concept definition : The strategy pattern defines a series of algorithms , And encapsulate each algorithm , And make them interchangeable , Let the algorithm be independent of the client using it
Application scenarios : Multiple ways to deal with the same problem , The difference in behavior
UML chart :

There are three concepts involved here : The policy abstract class itself , Holders of abstract classes , Specific strategies of abstract classes ( It can be understood as implementing subclasses )
for instance : stay iOS A news of app On the news list cell style , There may be three kinds :a: Plain text display b: Pure picture display c: Video display abc The specific implementation of the three styles is the specific strategy , Abstract style classes are policy abstract classes , Suppose that UITableViewCell To load these styles ,UITableViewCell It can be the holder of an abstract class . When using styles , By calling the load style method of the abstract class , And pass parameters to instantiate different styles .
reflection :1. Using the policy pattern , You have to know all the policy classes , And decide which policy class to use ?
2. Policy patterns can use inheritance as appropriate , Transfer the common part to the abstract class , But it will cause if you don't use abstract classes , It will lead to the incompleteness of the public part of the strategy method ? So we should pay attention to the appropriate trade-offs ?
3. Behavior classes that use policy methods ( Judge where to use ) It can be completely separated from specific strategies and methods . In this way, the strategy and method can evolve independently ?
4. The policy pattern results in an independent policy class for each specific implementation , And in actual development , Several strategies and methods may be completed in a class in minutes , If you use the policy mode development, there will be many more files , Many kinds , Resulting in extended development time , How to choose ?
边栏推荐
- Draw Bezier curve through screen interaction
- [jailhouse article] base architectures for virtual physical computing (2018)
- Date (day 76)
- What projects can make money online? Is it reliable to be we media?
- U-boot-1.1.6 transplant notes (beginner)
- Detailed explanation of arm instruction CMP
- Some interview questions collected
- Data too long for column 'data' at row 1 and the garbled code caused by setting to longblob are solved. node-mysql
- node.express中req.body总是undefind解决
- JSON、
猜你喜欢

四、MFC工具栏、运行时类信息机制、运行时创建机制

【剑指Offer】模拟实现atoi
![[jailhouse article] base architectures for virtual physical computing (2018)](/img/ea/480d3e0743639d2f2e0d447b3ca050.png)
[jailhouse article] base architectures for virtual physical computing (2018)

R strange grammar summary

Addition, deletion, modification and query of DOM elements
![[sword finger offer] analog implementation ATOI](/img/01/76a3b1fcc6403368a363146d553777.png)
[sword finger offer] analog implementation ATOI

C#--MetroFramework框架调用metroModernUI库,并在工具栏使用

It is said that screentogif is a GIF recording artifact, but I don't know that its strength is far from here

Design of automatic machine dot drawing script based on C language

【C】程序环境和预处理
随机推荐
Mysql database backup and recovery
The most comprehensive multi-threaded application tutorial - summary in detail
C language -c51 compilation warning "* * * warning l1: unresolved external symbol" and extern
Easy to understand: basic knowledge of MOS tube
[jailhouse article] base architectures for virtual physical computing (2018)
Blocking Queue Analysis
What projects can make money online? Is it reliable to be we media?
4、 MFC toolbar, runtime class information mechanism, runtime creation mechanism
ARM裸板调试之JTAG调试源码级调试
“蔚来杯“2022牛客暑期多校训练营2 Link with Game Glitch (spfa找正负环)
日期(DAY 76)
This is how the permission system is designed, yyds
MySQL index collation summary
What does "TTL" mean in domain name resolution?
The code of Keil and Si compiler is not aligned??
mysql数据库备份和恢复
【Node】服务端口被占用Error: listen EADDRINUSE: address already in use :::9000-如何关闭node启动的端口
"Everyday Mathematics" serial 61: March 1
二叉搜索树(DAY 75)
Use of golang exec.command