简体   繁体   English

生成器与立面设计模式

[英]Builder vs Facade design pattern

I have come across different creational and structural design patterns. 我遇到了不同的创作和结构设计模式。

In builder it have three sections and director will decide the order of execution. 在构建器中,它分为三个部分,主管将决定执行顺序。

When i gone through the facade pattern, it also follows the same method that is sequential order of actions. 当我浏览外观模式时,它也遵循相同的方法,即动作的顺序。

So what is the difference of both these pattern? 那么这两种模式有什么区别? When Facade pattern also refers to creation of objects and order of execution , how it fall under structural design pattern? 当Facade模式也指对象的创建和执行顺序时,它如何属于结构设计模式?

Well, according to dofactory , Facade is : 嗯,根据dofactory ,Facade是:

providing a unified interface to a set of interfaces in a subsystem. 为子系统中的一组接口提供统一的接口。 Façade defines a higher-level interface that makes the subsystem easier to use Façade定义了更高级别的界面,使子系统更易于使用

And Builder : 和生成器:

Separate the construction of a complex object from its representation so that the same construction process can create different representations. 将复杂对象的构造与其表示分开,以便同一构造过程可以创建不同的表示。

So it's quite obvious from descriptions that Facade pattern does not provide a way of constructing new objects. 因此,从描述中可以很明显地看出Facade模式没有提供构造新对象的方法。 Facade is a simplified high-level interface that you can use to access a set of sub-interfaces. Facade是简化的高级界面,可用于访问一组子界面。 Builder describes a way of creating objects. Builder描述了一种创建对象的方法。 For example the only purpose of StringBuilder class is to provide an effective way of creating new strings (yes, it is based on Builder pattern). 例如, StringBuilder类的唯一目的是提供一种创建新字符串的有效方法(是的,它基于Builder模式)。

A facade is just a way of simplifying calls in an object model so you don't have to write a large amount of code each time you want to perform a set of actions. 外观只是简化对象模型中的调用的一种方式,因此您不必每次要执行一组操作时都编写大量代码。 For example you might write a facade to simplify something which has to call several objects and methods in order to perform a task. 例如,您可能编写了一个Facade来简化某些事情,该东西必须调用多个对象和方法才能执行任务。

For more info: See the answers to this 有关更多信息: 请参阅答案

A builder is just a sort of facade used to simplify the construction logic of a class or set of classes. 生成器只是一种用于简化一个类或一组类的构造逻辑的外观。 Its purpose is quite often to provide a clear set of methods that make it clear how you are constructing the target object(s) and to give the construction a fluent feel. 它的目的通常是提供一组清晰的方法,以使您清楚如何构造目标对象,并使结构流畅。

builder.WithFirstName("John").WithLastName("Smith").WithStandardCompanyAddress().Build();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM