当前位置:网站首页>How to solve too many if statements
How to solve too many if statements
2022-07-23 12:47:00 【liangdu_ Zuker】
How to solve if Too many sentences
【 Use strategic mode 】 Define a policy base class , Then for each if Implement a policy subclass , Then use the parameters passed in , To match the adopted strategy , It's sort of like the idea of divide and rule .
【 Use sentinel pseudo nodes 】 We usually use if To judge the boundary problem , For non boundary problems, there is no need to use if, Then I just need to add the previous and subsequent sentinel pseudo nodes to the current boundary problem , You can do it without using if Statement .
【 Use drive table mode 】, Create a actionmap,key That's our condition case, value It's for this case Corresponding processing function handle. This can also avoid writing a lot if .
【 Use the responsibility chain model 】, namely , Will be multiple if, Divide into n Group if, every last if The group is encapsulated into a responsibility chain node , Then pass the parameters to the responsibility chain , The nodes of the responsibility chain pass judgment . With this layer of encapsulation of the responsibility chain , There won't be a bunch of hard to read if Statements are stacked .
边栏推荐
- Unity3D+moba+技能指示器(二)
- How to write a web page with a common text editor
- SQL server performance analysis, view slow queries
- Unity3d:ugui, UI and special effect particle level, bakemesh above 2018.2, particles between two images and in Scrollview
- Unity3d+GameFramework:资源分析,资源依赖,循环依赖检测
- Analysis ideas of strong consistency and weak consistency and concurrency skills of distributed scenarios
- @RequiredArgsConstructor注解使用
- 线程池总结
- 剑*offer—— 链表逆序
- 0最短路径问题 LeetCode743. 网络延迟时间
猜你喜欢

MySQL performance optimization, index optimization

Unity3d:UGUI,UI与特效粒子层级,2018.2以上版本BakeMesh,粒子在两个Image之间且在ScrollView

@RequiredArgsConstructor注解使用

Unity3d+GameFramework:资源分析,资源依赖,循环依赖检测

HCIP---BGP ---边界网关协议

OSPF的链路扩展配置

Implementation of binary tree -c

Unity3d:ugui, UI and special effect particle level, bakemesh above 2018.2, particles between two images and in Scrollview

Hcip--- BGP related configuration (Federal chapter)

HCIP---GRE协议和MGRE环境,以及OSPF协议的相关知识点
随机推荐
详解TCP的流量控制机制与拥塞控制机制
linkerd服务网格调研笔记
Unity3d+GameFramework:资源分析,资源依赖,循环依赖检测
前缀和 LeetCode2100. 适合打劫银行的日子
LeetCode题解汇总
Unity3d:场景加载 GameObejct上脚本执行顺序
Basic knowledge of high voltage technology
Briefly describe the similarities and differences between raft and Paxos in design
MySQL performance optimization, index optimization
[bootloader architecture and brushing process based on UDS service]
PDF Online preview, use of pdf.js
MySQL性能优化,索引优化
0回溯/动态规划中等 LeetCode526. 优美的排列
第一类错误离我们有多远
Implementation of binary tree -c
0数组 LeetCode605. 种花问题
详解TCP连接的释放
0最短路径问题 LeetCode743. 网络延迟时间
学习日记——(路由与交换技术)网络地址转换 NAT技术
*offer--2