Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 639
user1357872 Avatar asked Sep 19 '16 16:09

user1357872


2 Answers

Well, according to dofactory, Facade is :

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

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 is a simplified high-level interface that you can use to access a set of sub-interfaces. Builder describes a way of creating objects. 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).

like image 25
Fabjan Avatar answered Nov 09 '22 22:11

Fabjan


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.

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();
like image 89
gmn Avatar answered Nov 09 '22 22:11

gmn