Facade (appearance, facade)
An external user object interacts with a sub-system through a uniform facade object. The facade mode is a set of interfaces in the subsystem, providing a uniform facade for external objects to access. That is, the facade mode defines a higher level interface for external objects to use this subsystem easily.
Applicability:
1. You want to provide simple interfaces for a complex subsystem.
2. CustomerProgramThere is a large degree of dependency between the implementation part of the abstract class.
3. When you need to build a layered sub-system, use the facade mode to define each previous entry in the sub-system. If subsystems are mutually dependent, you can allow them to communicate only through facade, thus simplifying the dependency between them.
4. In the distributed system, to reduce the number of remote calls by the client, the facade mode is used to effectively reduce remote calls.
Structure:
1. facade (cfacade): the facade object is a coordinator who knows that the sub-system class needs the corresponding requests to implement those functions. He is responsible for entrusting client requests to appropriate subsystem objects.
2. subsystem (csubsystem): it is responsible for implementing the functions of the subsystem. It can be called either by a facade object or by a client directly. They do not know the facade object and do not need to maintain the reference with the facade object.
When working in the facade mode, the client that uses the facade object does not need to directly access the subsystem object. Instead, the facade object transmits the client request to the appropriate subsystem object, allowing the subsystem object to complete the actual work. This means that the facade object calls the method of the relevant subsystem and converts the subsystem interface to the interface required by the client. It turns out that the client needs to deal with multiple subsystems, and now it becomes a client that only deals with one facade object. This reduces the dependency and complexity between systems.