设计模式之Frameworks 框架(一)

2014-11-24 08:24:17 · 作者: · 浏览: 4
A framework is a set of cooperating classesthat make up a reusable design for a specific class of software [Deu89, JF88].For example, a framework can be geared
toward building graphical editors fordifferent domains like artistic drawing, music composition, and mechanical CAD[VL90, Joh92]. Another framework can help
you build compilers for different programming languages and target machines [JML92]. Yet another might help you build financial modeling applications [BE93].
You customize a framework to a particular application by creating application-specific subclasses of abstract classes from the framework.
框架是软件的特殊类,它们构成了实现重用设计的一 类;举个简单的例子,
对于不同的域像绘画艺术、音乐创作、机械CAD,框架可以针对这些建立图像编辑。其他的框架可以为不同的程序语言和目标机器建立编译。另一个可以帮助你建立最后的应用模型。通过创建框架抽象类的特殊的子类,你可以为你的应用定制一个框架。
The framework dictates the architecture of your application. It will define the overall structure, its partitioning into classes and objects, the key responsibilities thereof, how the classes and objects collaborate, and the thread of control. A framework predefines these design parameters so that you, the application designer/implementer, canconcentrate on the specifics of your application. The framework captures thedesign decisions that are common to its application domain. Frameworks thusemphasize design reuse over code reuse, though a framework will usually include concrete subclasses you can put to work immediately.
框架指定了你的应用的体系结构。它会定义主体结构,它划分的类和对象,主要职责,类和对象之间是如何协作,和它是如何控制的。框架预定义了应用设计和实现这些设计参数,因此你可以专心致志于你的应用中特殊的地方。框架捕捉应用中普遍的设计决策。框架强调设计重用超过代码的重用,虽然框架包含了你可以立即投入使用的子类!
Reuse on this level leads to an inversion of control between the application and the software on which it's based. When you use a toolkit (or a conventional subroutine library for that matter), youwrite the main body of the application and call the code you want to reuse. When you use a framework, you reuse the main body and write the code it calls. You'll have to write operations with particular names and calling conventions, but that reduces the design decisions you have
to make.
在这个水平的重用会导致应用程序之间和它所基于的软件控制的反转。当你使用工具包(或者传统的子程序库),你写了应用的主体和你想去重用的代码。在你使用框架的时候,你可以重用程序的主体和它调用的代码。你会用特殊的名字和调用协议来写一个运算,但是这些减少了你所使用的设计决策。
Not only can you build applications fasteras a result, but the applications have similar structures. They are easier to maintain,and they seem more consistent to their users. On the other hand, you losesome creative freedom, since many design decisions have been made for you.
结果是你不仅可以很快的创建应用并且应用有相似的结构。它们很容易去维护,用户看上去很一致。另一方面,从你开始使用你创建的设计决策,可能会失去一些设计的灵活性。
If applications are hard to design, andtoolkits are harder, then frameworks are hardest of all. A framework designergambles that one architecture will work for
all applications in the domain. Anysubstantive change to the framework's design would reduce its benefits considerably,since the framework's main contribution
to an application is the architecture it defines. Therefore it's imperative to design the framework to be as flexible andextensible as possible.
如果应用很难设计,用工具包很费劲,这框架也很难。框架为在应用的作用域中起作用冒很大的风险。从框架开始作用在这个应用开始,任何实质性的改变都会对框架的益处带来相当大的改变。框架必要的设计一定要灵活和可扩展。
Furthermore, because applications are sodependent on the framework for their design, they are particularly sensitive tochanges in framework interfaces. As
a framework evolves, applications have toevolve with it. That makes loose coupling all the more important; o