Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Facade and Gateway design patterns?

or Facade==Gateway?

like image 404
antz Avatar asked Dec 12 '10 14:12

antz


People also ask

Is API gateway facade pattern?

The pattern is similar to the facade pattern from object-oriented design, but it is part of a distributed system reverse proxy or gateway routing, and uses a synchronous communication model. The pattern provides a reverse proxy to redirect or route requests to your internal microservices endpoints.

What is the difference between facade and factory pattern?

The main difference between factory and facade design pattern is that factory is a creational design pattern that defines an interface or an abstract class to create an object, while the facade is a structural design pattern that provides a simplified interface to represent a set of interfaces in a subsystem to hide ...

What is a gateway pattern?

The gateway pattern or API gateway pattern is an integration pattern for clients communicating with your system services and acts as a single entry point between client apps and microservices. It is designed to provide a buffer between the underlying services and the client's needs.

What is difference between facade and proxy pattern?

The proxy pattern is where one object acts as an interface to another object. The difference between proxy and facade patterns are that we can proxies create interfaces for one object. But facades can be interfaces for anything. We use the proxy to call both foo and bar in obj .


Video Answer


2 Answers

Reviewing Facade in the GoF book and the link in another answer to Martin Fowler's Gateway, it appears that their focus is in opposite directions.

Facade provides a simple uniform view of complex internals to (one or more) external clients;

Gateway provides a simple uniform view of external resources to the internals of an application.

This distinction lets us focus on which is more important in a design:

With the Facade, the external system is our customer; it is better to add complexity facing inwards if it makes the external interface simpler.

With the Gateway, the internal system is our customer; give it all the help we can, even if the externals are more complex.

like image 156
user_1818839 Avatar answered Oct 05 '22 07:10

user_1818839


These two patterns are very similar in the way that both they serve as wrappers over something. The difference is in the context: facade stands over a group of subsystems, while gateway can be standing over any functionality. From this point of view, to me Facade is the concrete case of Gateway (not opposite).

Facade is applied when we think that working with subsystems is complex or if we want to group several subsystem calls into one [method] execution. However, this does not necessarily mean that subsystems are not accessible, or that they are complex enough. It simply means that we have subsystems.

Gateway is applied when we want to wrap some things and expose them into different way. Gateway may be wrapping not a subsystem, but just a relatively complex functionality. Gateway is a general pattern which can be thought as a basis for Facade, Proxy, and other patterns.

If example is still needed for clarification:

Facade can calculate credit worthiness of a customer by querying checking accounts subsystem, credit accounts subsystem, savings subsystem, and back office subsystem (I guess I have seen similar example in GOF books).

class MortgateFacade {     bool IsCreditWorth(string customerName) {         return !_checkingAccSystem.HasNegativeBalance(customerName) && !_creditAccSystem.HasNegativeCredit(customerName) && !_backOfficeSystem.IsInBlackList(customerName);     } } 

Gateway can query the database table and return customer by ID. (Yes, that simple!)

class CustomersGateway {     Customer GetCustomer(int id) {         return _db.ExecuteOne("SELECT TOP 1 FROM CUSTOMERS WHERE CUSTOMER_ID="+id).AsCustomer();     } } 

[Obviously this is a pseudo code]

like image 29
Tengiz Avatar answered Oct 05 '22 06:10

Tengiz