or Facade==Gateway?
相关问题
- Name for a method that has only side effects
- What is a correct approach to manage test data usi
- Can a [GoF]-ConcreteSubject override the notify me
- Can the builder pattern ever be doing too much?
- Carry STRef implicitly in an environment during co
相关文章
- 求助!Feign调用报错:No qualifying bean of type 'org.
- Builders in Java versus C++?
- “Adapter” or “adaptor”?
- Is copy-and-paste coding ever acceptable?
- How to Create a Custom tabBarController to simulat
- Dependency Injection Container
- Design pattern for managing queues and stacks?
- JS loop variable scope
A facade pattern main value is to 'simplify' use of internal components (behind the facade). It could be so that one entry point or function in the facade will use multiple functions of the internal components. If a gateway is bringing the same value of 'simplifying' usage of APIs or components behind it then it could be considered a facade. In other situations, a gateway could be merely a middleware, adapter, wrapper or a call forwarding element of the architecture. Or a gateway could be wearing multiple hats, like simplifying few flows, forwarding some calls while acting as an authentication or authorisation middleware in parallel too. Thus, IMHO gateway is a highly abstract pattern that could encompass one or more specific structural patterns like facade, adapter, wrapper, decorator or middleware etc..
Martin Fowler definition of gateway is narrow in nature (at least the one here) and is closer to API Gateways acting like format decorators.
As far the implementation is concerned, there is no limit on what a gateways could and could not do. It is virtually an application of its own and could deliver any functionality.
Here's the direct quote from Fowler's book:
[Chapter 18]
Simply put, Facade is a design pattern while Gateway is an architectural pattern.
Application Gateway, for example, is an infrastructure architecture pattern. The node resides in DMZ and insulates internal nodes from external clients who can only connect to application gateway.
When you think about architecture patterns, think about nodes. When you think about design patterns, think about classes/objects.
Node is an abstraction of: device - hardware stuff and system software - e.g. OS, platform/framework etc. System software is "assigned" to the device. Node "encapsulates" both device and system software and is related to other nodes comprising the architecture.
Gateway is a node that insulates server nodes from client nodes - client node cannot directly connect to a server node. Gateway receives the connection and then establishes connection itself to the destination node.
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.
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).
Gateway can query the database table and return customer by ID. (Yes, that simple!)
[Obviously this is a pseudo code]
I think Gateway is a specific case of Facade - a facade over an external system.