Q1: What is the difference between State and Strategy patterns? {#Q1}
状态模式和策略模式之间有什么区别
While the implementation is similar they solve different problems. The State
pattern deals with what state an object is in - it encapsulates state-dependent
behavior.
The Strategy pattern deals with how an object performs a certain task - it
encapsulates an algorithm.
虽然这两种设计模式实现非常类似,但是他们解决了不同的问题,状态模式处理对象所处的状态,封装了依赖于状态的行为,
策略模式处理对象如何执行特定的任务,它封装的是算法
Q2: What is the difference between Strategy and Template Method patterns? {#Q2}
策略模式和模板方法模式的区别
In Template Method the algorithm is chosen at compile time via inheritance.
With Strategy pattern the algorithm is chosen at runtime via