Chapter 01 Intro to Design Patterns
第01章 设计模式入门
1. Design Principle Identify the aspects of your application that vary and separate them from what stays the same. (P9)
设计原则:找出应用中可能需要变化之处,把它们独立出来,不要和那些不需要变化的代码混在一起。
2. Design Principle Program to an interface, not an implementation. (P11)
设计原则:针对接口编程,而不是针对实现编程。
3. Design Principle Favor composition over inheritance. (P23)
设计原则:多用组合,少用继承。
4. 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. (P24)
策略模式:定义了算法族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化独立于使用算法的客户。
Chapter 02 the observer pattern
第02章 观察者模式
1. The Observer Pattern defines a one-to-many dependency between objects so that one object change state,all of its dependents are notified and updated automatically. (P51)
观察者模式:定义了对象之间的一对多依赖,这样一来,当一个对象改变状态时,它的所有依赖者都会收到通知并自动更新。
2. Design Principle Strive for loosely coupled designs between objects that interact. (P53)
设计原则:为了交互对象之间的松耦合设计而努力。
3. Loosely coupled designs allow use to build flexible OO systems that can handle change because they minimize the interdependency between objects. (P53)
松耦合的设计之所以能让我们建立有弹性的OO系统,能够应对变化,是因为对象之间的互相依赖降到了最低。
Chapter 03 the decorator pattern
第03章 装饰者模式
1. Design Principle Classes should be open for extension, but closed for modification. (P86)
设计原则:类应该对扩展开放,对修改关闭。
2. Be careful when choosing the areas of code that need to be extended; applying the Open-Closed Principle EVERYWHERE is wasteful, unnecessary, and can lead to complex, hard to understand code. (P87)
在选择需要被扩展的代码部分时需要小心。每个地方都采用 开放-关闭 原则是一种浪费,也没必要,还会导致代码变得复杂而且难以理解。
3. The Decorator Pattern attaches additional responsibilities to