码迷,mamicode.com
首页 > 其他好文 > 详细

Builder创建者模式

时间:2015-05-27 20:41:45      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:

http://www.codeproject.com/Articles/42415/Builder-Design-Pattern

 

In Elizabeth‘s day care center, the teacher helps the kids to build all kinds of toys to develop their creative skills. One of Elizabeth‘s favorite activities is to make animals with play-dough.

在伊丽莎白所在的托儿所,老师帮助孩子们,构造各种各样玩具来开发孩子们的创造能力。伊丽莎白最喜欢的一个活动是用橡皮泥来做动物。

A set of molds is the tool that Elizabeth always uses to create her favorite cool animals.

一套模具,是伊丽莎白经常用来创造她最喜欢最酷的动物的工具。

One mold tool set includes five parts, including the head, body, arm, leg, and tail. Whenever Elizabeth wants to build an animal, she will use one set of each tools to make a head, body , leg, arm, and tail for that animal, and then assembles them with glue to build an animal. 

一套模具包含五个部分,包括头、身体、手臂、腿、尾巴。无论何时,当伊丽莎白想要构造一个动物的时候,她就会使用那个动物模具中分别来做 头、身体、腿、手臂以及尾巴。最后用胶水把它们粘起来,组成一个动物。

There are many types of animal mold tool sets that the kids can choose from.

这里有许多类型的动物模具让孩子们可以进行选择。

For example: if Elizabeth wants to make a monkey, then she will pick the set of monkey molds to start.

例如:如果伊丽莎白想要做一个猴子,那么她会挑选出猴子模具做一下步骤:

  • Step 1. Make monkey head.
  • Step 2. Make monkey body.
  • Step 3. Make monkey leg.
  • Step 4. Make monkey arm.
  • Step 5. Make monkey tail.

Once all the five parts are finished, then Elizabeth will glue them all together and decorate it to have a monkey done as a finished product.

一旦五个部分完成了,那么伊丽莎白就会用胶水把它们粘起来,最后装饰一下它,就可以得到一个完成的作品,一个猴子。

Most likely, she will give it to me or her mom as a gift when we pick her (she will not give us the monkey if the monkey is not decorated, since it will not be looking good at all then).

在我们去托儿所接她的时候,大多数情况下,她会把这个猴子作为礼物送给我或者她的妈妈。(在猴子没有装饰之前,它不会把猴子给我们,因为没有装饰前,它一点都不好看)

When she wants to make a kitten, she follows the same steps with the set of Kitten molds.

当她想要做一个小猫的时候,她使用小猫的模具,按照相同的步骤来处理。

In the above scenario, an Builder Design Pattern is perfectly used by Elizabeth in her daily fun activities.

在上述情景中,伊丽莎白在她有趣的日常活动中完美地使用了创建者模式

 

Introduction

The Builder Design Pattern helps us to slice the operations of building an object.

创建者模式帮助我们分解创建一个对象的操作

 

It also enforces a process to create an object as a finished product.

它会确保创建一个对象作为完成的产品是按照一个程序来执行的。

 

That means an object has to be massaged by some instructed steps before it is ready and can be used by others.

The massage process could apply any restrictions or business rules for a complete building procedure (or a procedure we follow to make an object that is considered as a ready to use object).

For instance, to compose an email, you can‘t leave the To and Subject fields blank before you can send it.

In other words, an email object will be considered as an uncompleted email object (a common business rule for email) if those two fields are not filled.

It has to be built (filled) before we can send it out.

This article introduces an implementation of how we use the Builder Design Pattern for Elizabeth‘s fun activity.

 

Builder创建者模式

标签:

原文地址:http://www.cnblogs.com/chucklu/p/4534254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!