设计模式之 Designing for Change 变更设计(一)

2014-11-24 09:26:35 · 作者: · 浏览: 4
The key to maximizing reuse lies in anticipating new requirements and changes to existing requirements, and in designing your systems so that they can evolve accordingly.
变更设计的关键是在预测新的要求和变更已存在的要求时最大限度的重用,在你设计的系统中可以进行相应的设计。
To design the system so that it's robust tosuch changes, you must consider how the system might need to change over itslifetime. A design that doesn't take change into account risks major redesign inthe future. Those changes might involve class redefinition and reimplementation,client modification, and retesting. Redesign affects many parts of the softwaresystem, and unanticipated changes
are invariably expensive.
为了让你设计的系统在面对诸多的改变时显得健全,需要考虑在这个系统的生命周期内出现的所有变化。在未来的时候,设计不能冒重新设计的风险。这些变更可能会涉及到类的重定义和类的实现,客户端的修改,重新测试。重新设计影响了软甲系统的很多的部分,意想不到的变化花钱更多。
Design patterns help you avoid this by ensuring that a system can change in specific ways. Each design pattern lets some aspect of system structure vary independently of other aspects, thereby making a system more robust to a particular kind of change.
设计模式通过一些特殊的方法确保 系统可以应对这些变更,帮助你避免这些问题。设计模式会让系统结构的某些方面和其他的方面之间最大限度的独立,因此会让系统在应对各种特殊的变化时显得更健全。
Here are some common causes of redesign along with the design pattern(s) that address them:
这里有常见的设计模式连同它们的位置
1. Creating an object by specifying a class explicitly. Specifying a class name when you create an object commits youto a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objectsindirectly.
Design patterns: Abstract Factory (99),Factory Method (121), Prototype (133).
(1)通过指定的显式类创建对象。指定类的名字,当你创建对象保证特殊的实现来代替特殊的接口。这些可以为未来复杂的变化做贡献。为了避免这个问题,间接的创建对象。
设计模式:抽象工厂,工厂模式,原型模式
2. Dependence on specific operations. When you specify a particular operation,you commit to one way of satisfying are quest. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time.
Design patterns: Chain of Responsibility(251), Command (263).
(2)依赖特殊的运算。你通过指定特殊的运算的方法来满足要求。通过避免编码要求,在编译和运行时,可以很容易的变更方法来满足要求。
设计模式:职责链模式,命令模式
3. Dependence on hardware and software platform. External operating system interfaces and application programming interfaces (APIs) are different on different hardware and software platforms.Software that depends on a particular platform will be harder to port to other platforms. It may even be difficult to keep it up to date on itsnative platform. It's important therefore to design your system to limit its platform dependencies.
Design patterns: Abstract Factory (99),Bridge (171).
(3)依靠硬件或软件平台。在不同的软件或硬件平台上,外部运算系统接口和应用程序接口是不同的。软件依赖特殊的平台将会很难移植到其他的平台。甚至可能在它本身的平台上保持数据的更新都很困难。因此在设计你的系统时平台的独立性很重要。
设计模式:抽象工厂,桥接模式
4. Dependence on object representations or implementations. Clients that know how an object is represented, stored,located, or implemented might need to be changed when the object changes.Hiding this information from clients keeps changes from cascading. Design patterns: Abstract Factory (99),Bridge (171), Memento (316), Proxy (233).
(4)依靠当前对象和对象的实现。当一个对象变更时,客户知道对象如何表示、存储和它的位置以及可能需要变更的实现。从客户不断变化的级联中隐匿这些信息
设计模式:抽象工厂,桥接模式,备忘录模式,代理模式
5. Algorithmic dependencies. Algorithms are often extended, optimized, and replaced during development and reuse.Objects that depend on an algorithm will have to change when the algorithm changes.