The company's ordinary day ... (铃 电话 电话 电话 响) Customer (for developers): When is your software? Isn't it handed on Tuesday ..... Little Sun (for customers) : This question, you have to contact our boss ... (customer and boss passionate discussion ...) boss (for developers): Xiao Zhong, Xiaosun, you solve this problem together ... Boss (for customers): We The next week is coming ... Here, the boss is Facade, the customer does not need to be deal with the Development Department, all matters contact the boss (unless ...)
definition
Name: FACADE Structure: Titting: Provides a consistent interface for a set of interfaces in the subsystem, and the FACADE mode defines a high-level interface, which makes this subsystem easier to use. Applicability: When you want to provide a simple interface for a complex subsystem. Subsystems tend to become more complicated because of continuous evolution. Most mode uses more smaller classes. This makes the subsystem more reusability, and it is more easier to customize the subsystem, but this also brings some difficulties to those users who do not need to customize subsystems. FACADE provides a simple default view that is enough for most users, and those users who need more customizable can cross the FACADE layer. There is a lot of dependence between the client program and the abstract class. Introducing FACADE to separate this subsystem from customers, and other subsystems, can increase the independence and portability of the subsystem. When you need to build a subsystem of a hierarchy, use the FACADE mode to define the entry points in the subsystem. If the subsystem is interdependent, you can make them communications with FACADE, which simplifies the dependence between them.
Classic Case
1, J2EE: Session Facade (session appearance)
In the J2EE application environment, there are many EntityBeans that implement related functions. This time you have to make the user application to perform each operation, create an Entity, then not only achieve complex, and the efficiency is extremely low, if you use a session as Facade, Then add a lot of problems.
Reference EJB Design Mode Overview
Http://dev2dev.bea.com.cn/techdoc/other/20031085.html
J2EE architecture design http://www.sawin.com.cn/doc/sd/architect/j2eemvc.htm
Best Practices
1. Many projects are very likely to deal with other systems in the development process. In the process, we don't need to use all the interfaces of other systems. In this case we can use the FACADE mode. Pack all the features we need to use, make some functions, or even classes to facilitate the use of this project. If you clearly list the places where you may need to use in the current project, then just a few people to understand, and organize the interface, others only need to call these interfaces directly, save time.
2. Use Facade to hierarchically, provide a simple abstract interface between Layer-Layer.
Related mode
1, Facade vs Proxy
Facade mode is translated into a facade pattern, which is a very image.
I have many components here to provide a lot of services, and one end of the call is to deal with these components, you can think of a multi-to-many relationship. The FACADE mode is to provide a common facade for the components of these services. If you call the place to access these services, you can't afford to find components directly, find me, I will help you get it, you can think of more one and one pair Many relationships. And Facade is the middle "one", which is a portal.
Proxy mode is a proxy mode, which provides an agent to an agent to control other objects to him.
For example, protect the agent, you have to control the object you have access to the agent, that is, you want to visit XXX, you must pass me.
Of course, Proxy is not necessarily used to control privileges, such as what can be made to do some logs before and after being executed by the method of the agent object. Note that the proxy and the object of the agent are implemented the same interface. 2, Facade vs Adapter
Adapter is used to match two interfaces, while Facade is used to package a set of interfaces.
If you get a toolkit, what method you can use to reuse the classes in the toolkit.
In fact, the choice is obvious. For me, Adapter is a white box multiplex, and Facade is a black box multiplexed. The so-called white box is multiplexed, that is, you are using Adapter to know the interface of Adaptee, then you inherit from its interface (class adptee) or assign the operation on your own interface to Adaptee (Object Adaptee). The black box is reused, that is, your toolbox or others are realized, then you can use Facade directly instead of inheritance.
The second question is that when you implement FACADE, in general, there is a strong coupling between subsystems or classes included in Facade. When other people want to use these classes, a series of objects are often created. Process, while you need to call many classes to implement a feature, this time you prefer to pack, a good example of Facade's specific application is in the J2EE application environment, there is a lot of EntityBean for implementing related features. At this time, if you want the client application to perform each operation, create an Entity, then not only make complex, and the efficiency is extremely low, if you use a session as facade, there will be a lot of problems.
Other important roles of FACADE include hierarchical interfaces between the architecture, providing a simple abstract interface between Layer-Layer, and AdPater is primarily applied to a localized implementation of the system.
There may be a lot of ways to say, the design of design patterns should be started from actual, if you often use these things in practice, you often go to Refactor for your previous procedures, so many things are natural.
Reference article
1, EJB design mode overview
Http://dev2dev.bea.com.cn/techdoc/other/20031085.html
2,
J2EE architecture design http://www.sawin.com.cn/doc/sd/architect/j2eemvc.htm3, one of Pattern Tips (explaining Adapter, Bridge, Facade, PROXY is different, Pattern TIPS series focuses on GOF design mode The relationship between http://www.vckbase.com/Document/viewdoc/?id=751