Facade pattern - Wikipedia, the free encyclopedia
A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can:
Intent
By introducing the Facade into your code, you will be hardwiring subsystems into the Facade. This is fine if the subsystem never changes, but if it does, your Facade could be broken. Therefore, developers working on the subsystem should be made aware of any Facade around their code.
Example:
StoreKeeper, Store,
Common Mistakes while Implementing Facade Design Pattern
http://javapapers.com/design-patterns/facade-design-pattern/
In JDK
http://www.allapplabs.com/java_design_patterns/facade_pattern.htm
This is how facade pattern is used. It hides the complexities of the system and provides an interface to the client from where the client can access the system. In Java, the interface JDBC can be called a facade. We as users or clients create connection using the “java.sql.Connection” interface, the implementation of which we are not concerned about. The implementation is left to the vendor of driver.
Read full article from Facade pattern - Wikipedia, the free encyclopedia
A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can:
- make a software library easier to use, understand and test, since the facade has convenient methods for common tasks;
- make the library more readable, for the same reason;
- reduce dependencies of outside code on the inner workings of a library, since most code uses the facade, thus allowing more flexibility in developing the system;
- wrap a poorly designed collection of APIs with a single well-designed API (as per task needs).
Intent
- Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
- Wrap a complicated subsystem with a simpler interface.
- Facade
- The facade class abstracts Packages 1, 2, and 3 from the rest of the application.
- Clients
- The objects are using the Facade Pattern to access resources from the Packages.
- Important Points
- Facade pattern is more like a helper for client applications, it doesn’t hide subsystem interfaces from the client. Whether to use Facade or not is completely dependent on client code.
- Facade pattern can be applied at any point of development, usually when the number of interfaces grow and system gets complex.
- Subsystem interfaces are not aware of Facade and they shouldn’t have any reference of the Facade interface.
- Facade pattern should be applied for similar kind of interfaces, its purpose is to provide a single interface rather than multiple interfaces that does the similar kind of jobs.
- We can use Factory pattern with Facade to provide better interface to client systems.
- Facade provides a single interface.
- Programmers comfort is a main purpose of facade.
- Simplicity is the aim of facade pattern.
- Facade design pattern is used for promoting subsystem independence and portability.
- Subsystem may be dependent with one another. In such case, facade can act as a coordinator and decouple the dependencies between the subsystems.
- Translating data to suit the interface of a subsystem is done by the facade.
By introducing the Facade into your code, you will be hardwiring subsystems into the Facade. This is fine if the subsystem never changes, but if it does, your Facade could be broken. Therefore, developers working on the subsystem should be made aware of any Facade around their code.
Example:
StoreKeeper, Store,
Common Mistakes while Implementing Facade Design Pattern
http://javapapers.com/design-patterns/facade-design-pattern/
- just for the sake of introducing a facade layer developers tend to create additional classes. Layered architecture is good but assess the need for every layer. Just naming a class as ABCDFacade.java doesn’r really make it a facade.
- Creating a java class and ‘forcing’ the UI to interact with other layers through it and calling it a facade layer is one more popular mistake. Facade layer should not be forced and its always optional. If the client wishes to interact with components directly it should be allowed to bypass the facade layer.
- Methods in facade layer has only one or two lines which calls the other components. If facade is going to be so simple it invalidates its purpose and clients can directly do that by themselves.
- A controller is not a facade.
- Facade is ‘not’ a layer that imposes security and hides important data and implementation.
- Don’t create a facade layer in advance. If you feel that in future the subsystem is going to evolve and become complicated to defend that do not create a stub class and name it a facade. After the subsystem has become complex you can implement the facade design pattern.
- Subsystems are not aware of facade and there should be no reference for facade in subsystems.
In JDK
http://www.allapplabs.com/java_design_patterns/facade_pattern.htm
This is how facade pattern is used. It hides the complexities of the system and provides an interface to the client from where the client can access the system. In Java, the interface JDBC can be called a facade. We as users or clients create connection using the “java.sql.Connection” interface, the implementation of which we are not concerned about. The implementation is left to the vendor of driver.
ExternalContext behaves as a facade for performing cookie, session scope and similar operations. Underlying classes it uses are HttpSession, ServletContext, javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse.
Read full article from Facade pattern - Wikipedia, the free encyclopedia