- 策略模式的本质:少用继承,多用组合。
- STRATEGY PATTERN DEFINITION: it defines a family of algorithms(算法?),encapsulate each one, and makes then interchangeable. strategy lets the algorithm vary independently from clients that use it.(策略模式是定义一组能够不断更变的algorithms, 把它们封装起来。)
- Identify the aspects of your application that vary and separate them from what stays the same.in other words, take the parts that vary and encapsulate them, so that later you can alter or extend the parts that vary without affecting those that don't.(确定应用程序中会变的和不变的因素, 把会变的部分封装成单独的组件。这是设计模式的本质所在。)
- SimUDuck(Strategy Pattern) Big Picture
- favor composition over inheritance(相对于继承,要善于用组合。)
- OBSERVER PATTERN DEFINITION: it defines a one-to-many relationship between a set of objects so that when one object changes state, all of it's dependents are notified and updated automatically.(观察者模式是定义了这样一种1对多的关系,当subject改变状态的时候,其他所有的observers都会被通知同时改变状态。)
- Observer Pattern Big Picture
- When two object can interact, but they have very little knowledge of each other, then we call they are loosely coupled, as the observer pattern.(当两个对象能够相互作用,但它们对对方知道的都特别少,这时候我们就说它们是松耦合的。观察者模式就是这样的,subject和observer是松耦合的。)
- Java build-in Observer Pattern Big Picture
设计模式金玉良言<一>
最新推荐文章于 2024-07-14 21:52:00 发布