什么时候应该使用构建器设计模式? [英] When should I use builder Design Pattern?

查看:55
本文介绍了什么时候应该使用构建器设计模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习设计模式,并找到了Builder设计模式。这种设计模式有什么好处,何时应使用?我在 www.dofactory.com www.blackwasp.com 上冲浪,但仍然不了解这样做的好处。顺便说一句,我是设计模式的新手,所以请用简单的方法向我解释一下。

I'm learning about Design Patterns and found the Builder design pattern. What are the benefits of this design pattern and when should I use it? I surf www.dofactory.com and www.blackwasp.com but still don't understand the benefits. By the by, I'm new to design patterns so please explain me with simple ones.

推荐答案

构建器设计模式可帮助我们对构建对象的操作进行切片。它着重于逐步构建一个复杂的对象。它还强制执行将对象创建为成品的过程。这意味着在准备好对象之前,必须先通过一些指示步骤对对象进行按摩,然后其他对象才能使用它。

The Builder Design Pattern helps us to slice the operations of building an object. It focuses on constructing a complex object step by step. 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.

通常,它允许您封装复杂的创建逻辑。

Generally, It allows you to encapsulate the complex create logic.

构建器模式非常类似于工厂模式。生成器与工厂之间的主要区别在于,当您需要做很多事情来构建对象时,生成器非常有用。

Builder pattern is very much like factory pattern. The key difference between a builder and factory is that a builder is useful when you need to do lots of things to build an object.

有关更多信息:

http://en.wikipedia.org/wiki/Builder_pattern

http://www.codeproject.com/KB/architecture/Builder_Design_Pattern.aspx

这篇关于什么时候应该使用构建器设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆