当前位置:网站首页>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 ?
边栏推荐
- Amazoncaptcha bypasses Amazon IP verification code with 95% success rate
- 日期(DAY 76)
- Machine learning keras fitting sine function
- What determines the "personality" of AI robots?
- Netease game Flink SQL platform practice
- Android interview question: why do activities rebuild ViewModel and still exist—— Jetpack series (3)
- [node] the service port is occupied error: listen eaddinuse: address already in use::: 9000- how to close the port started by node
- Application of first-order complementary filtering to STM32 ADC acquisition
- [QT] solve the problem of Chinese garbled code output from QT console
- Quick sort code implementation
猜你喜欢

Daily question brushing record (XXVIII)
![[ultra detailed diagram] FPN + mask RCNN](/img/ef/ddd62fe7e54074c134aa5ee4cc5840.png)
[ultra detailed diagram] FPN + mask RCNN

How does vscode enable multiple terminals? How to display horizontally?

C#控件开源库:MetroFramework的下载

ROI pooling and ROI align

Mlx90640 infrared thermal imager temperature measurement module development notes (I)

Do you know the same period last year in powerbi

【剑指Offer】模拟实现atoi

How to play a data mining game entry Edition
![[reprint] pycharm packages.Py program as executable exe](/img/9c/02a967fb08ca54bb742cf69c4578a7.png)
[reprint] pycharm packages.Py program as executable exe
随机推荐
Special episode of Goddess Festival | exclusive interview with Chinese AI goddess Zhang Qingqing's transformation from a female learning tyrant to a female entrepreneur
健康打卡每日提醒累了?那就让自动化帮你---HiFlow,应用连接自动化助手
Interlocked atom access series of functions
Memory memory operation function
Ceres solver version 1.14 and eigen3.2.9
Easy gene chip SEQ analysis method: practical workflow and advanced applications
How does vscode enable multiple terminals? How to display horizontally?
你了解PowerBI中的去年同期吗
Define usage method and template
【C】 Program environment and pretreatment
Ida Pro novice tutorial
Solve the problem of invalid modification of QT 5 interface. Solve the problem of invalid modification of qtdesigner
Clear wechat applet and wechat H5 cache
Blocking Queue Analysis
Classic cases of static keywords and block blocks
This is how the permission system is designed, yyds
Mysql database backup and recovery
JTAG debugging source level debugging of arm bare board debugging
[C language] in depth understanding of pointers and arrays (phase I)
Download and run the C open source control metroframework demo project