Façade mode C + + implementation 1 definition facade
The external interface of a subsystem is required to communicate with its internal communication through a unified interface. The façade mode provides a high-level interface that makes the subsystem easier to view
Note: The façade mode focuses on the unified object, which is the interface that provides an access subsystem, except that the interface does not allow any access to the subsystem's behavior to produce
2 class Diagram
Facade façade role, which is the only channel inside the outside access subsystem
subsystem subsystem role, which can be one or more subsystems at the same time, each subsystem is not a separate class but a collection of classes
3 implementation
Subsystem
Class ClassA
{
Public
void DoSomething ()
{
subsystem business logic
}
};
Class ClassB
{
Public
void DoSomething ()
{
subsystem business logic
}
};
Façade objects
Class facade
{
Private
ClassA A;
ClassB b;
Public
void Dosomethinga ()
{
A.dosomething ();
}
void Dosomethingb ()
{
B.dosomething ();
}
};
4 applications
① Advantages
Reduce system interdependencies
Increased flexibility
Improve security
② Disadvantages
does not conform to the opening and closing principle, closed to the modification, open to expansion. Because changes inside the system need to change the façade
③ Usage Scenarios
Provides an external access interface for a complex module or subsystem
subsystem is relatively independent--external access to the subsystem as long as the black box operation can
Prevention of risk spread by low-level personnel
④ precautions
The number of facades can be greater than one:
To the extent that the façade is too large to tolerate
Subsystems can provide different access paths
Note: The façade does not participate in the logical business within the subsystem---if the subsystem internal logic needs to be changed to the external, so long will be encapsulated, and then to the façade rather than let the façade processing logic
Design pattern--Façade mode C + + implementation