18

小白写了一堆if-else,大神实在看不下去了,竟然用策略模式直接摆平了-李宁的极客世界

 3 years ago
source link: https://blog.51cto.com/androidguy/2508085
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
策略模式的核心思想与 if else如出一辙,根据不同的key动态的找到不同的业务逻辑(要执行的函数)。那它就只是如此吗?实际上,我们口中的策略模式其实就是在代码结构上调整,用接口+实现类+分派逻辑来使代码结构可维护性更好。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK