Introduction
February 21, 2021 · View on GitHub
Defines a family of algorithms, encapsulates each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients who use it.
介绍
策略模式定义了算法家族,分别封装起来,让他们之间可以相互替换,此模式让算法的变化不会影响到使用算法的客户
本例解析
- 通过context对不同的策略进行封装,减小算法的改变对客户端的影响