英语翻译:开篇——抽象工厂

大学时代的时候英语就一直很差,到现在留下了个灾难,遇到英语文章就跳过,但是听师父说,国外的原创技术文章资源非常的丰富,而翻译过后的文章可能意思就有所偏差了,毕竟每个人的理解可能都不一样。所以从今天起呢,每天阅读一些技术文章然后进行翻译,在这里发布出来,也希望大家给予指正。

刚好最近再学设计模式,结合着看英语文章,今天就翻译一篇抽象工厂文章。

原文:

The abstract factory pattern is a software design pattern that provides a way to encapsulate a group of individual factories that have a common theme. In normal usage, the client software creates a concrete implementation of the abstract factory and then uses the generic interfaces to create the concrete objects that are part of the theme. The client does not know (or care) which concrete objects it gets from each of these internal factories since it uses only the generic interfaces of their products. This pattern separates the details of implementation of a set of objects from their general usage. 

抽象工厂模式是一个软件设计模式,它提供了一种方法用来封装一组有着共同主题的工厂。通常用法是客户端软件创建一个抽象工厂的具体实现,然后用通用接口来创建具体对象(主题的一部分)。客户端不知道(或者说不关心)具体对象来自哪个内部工厂,因为它用的是他们的产品的通用接口。这个模式从一组对象的一般用法中分离了对象的具体实现。

An example of this would be an abstract factory class DocumentCreator that provides interfaces to create a number of products (e.g. createLetter() and createResume()). The system would have any number of derived concrete versions of the DocumentCreator class like FancyDocumentCreator or ModernDocumentCreator, each with a different implementation of createLetter() and createResume() that would create a corresponding object like FancyLetter or ModernResume. Each of these products is derived from a simple abstract class like Letter or Resume of which the client is aware. The client code would get an appropriate instance of the DocumentCreator and call its factory methods. Each of the resulting objects would be created from the same DocumentCreator implementation and would share a common theme (they would all be fancy or modern objects). The client would need to know how to handle only the abstract Letter orResume class, not the specific version that it got from the concrete factory. 

一个例子是一个抽象类DocumentCreator 提供创建一些产品的接口(如:createLetter()和createResume())。系统应该有一些DocumentCreator 类的不同的子类比如FancyDocumentCreator或ModernDocumentCreator,他们分别实现了createLetter() 和createResume() 同来创建对应的像 FancyLetter 或者 ModernResume的类。每一个产品继承自像Letter 或 Resume这样的客户端知道的抽象类 。客户端代码将获得一个DocumentCreator 的相应实例然后访问它的工厂方法。每个结果对象被相同的DocumentCreator实现创建而且共有一个主题(都将是fancy 或者 modern 对象)。客户端只需要知道怎么处理是 Letter 或者Resume 的抽象类,不需要知道它怎么从具体的工厂来的。

In software development, a Factory is the location in the code at which objects are constructed. The intent in employing the pattern is to insulate the creation of objects from their usage. This allows for new derived types to be introduced with no change to the code that uses the base class. 

在软件开发中,工厂是类被创建的地方。使用这个模式的意图是把对象的创建从使用中隔离。我们可以在不改变基类的基础上引进派生类。

Use of this pattern makes it possible to interchange concrete classes without changing the code that uses them, even at runtime. However, employment of this pattern, as with similar design patterns, may result in unnecessary complexity and extra work in the initial writing of code. Used correctly the "extra work" pays off in the second instance of using the Factory.

用这个模式可以在不改变用到的代码的同时改变具体类,甚至是在运行时。然而同其他相似的设计模式一样,用这个模式可能会带来不必要的复杂性和写代码初期的额外工作量。正确使用“额外工作”回报在用工厂第二次实例化

posted on 2010-10-13 23:20  陌路vs追忆  阅读(241)  评论(0编辑  收藏  举报

导航