What is Facade Design Pattern?
Facade, pronounced as fuh-sahd, originated from french façade and italian facciata, meaning the face of a building, esp the main front or a front or outer appearance.
Lets see what it means in the world of design patterns.There are two important part of the problem it addresses:
a) The subsystems within a system
b) Interaction between subsystems of two different systems.
Sometimes the interaction becomes so complex, that we need to create a layer abstraction which can help in achieving simplicity by introducing simple interface to communicate.
Definition
Now lets see the official GoF definition, Facade Pattern: a single class that provides a unified interface to an entire subsystem.Use case or example of Facade
There are many use case if we look through the interactions between various systems and their components. One such example is the interaction that happens between various components in Supply Chain Domain. The below image explain one such interaction. Although this is not exact interaction but this pretty much explains the crux of Facade.
Important points to be noted
- We should implement it only when the complexity increases. If the interactions are simple, then we may like to keep it as it is. Remember, simplification is one of the intent behind Facade.
- The subsystems should be unaware of a Facade. Meaning, the subsystem should not hold/create an instance or reference of Facade.
How it is similar or different from other patterns?
Adapter : Facade and Adapter solves different problem area and have different intent. While Facade provides an interface to the existing subsystems or functions, Adapter works to fix any kind of gap in using one interface of a system. So, it is something which is done after a code/component is written and has to be "adapted" to work with a particular user or client. One example of Adapter can be OracleConnection interface which can be further used to execute on Oracle specific Types and it actually extends java.sql.Connection interface. A few interesting discussions are on following links:
References:
- http://dictionary.reference.com/browse/facade
- https://en.wikipedia.org/wiki/Facade_pattern
- http://c2.com/cgi/wiki?FacadePattern
- http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleConnection.html
No comments:
Post a Comment