策略模式定义了算法族,分别封装起来,让它们之间可以相互替换,此设计模式让算法的变化独立于使用算法的客户。 The Strategy Pattern defines a family of algorithms,encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
设计原则一:找出应用中可能需要变换之处,把它独立出来,不要和那些不需要变换的代码混在一起。 把会变化的部分取出并封装起来,以便以后可以轻松的改动或补充此部分,而不影响不需要变化的其他部分。