Intent:Provides a consistent interface for a group of interfaces in the subsystem. The facade mode defines a high-level interface, which makes the subsystem easier to use.
Structure:
Example:
Suppose you have a killer home theater system that includes a DVD player, a projector, an automatic screen, and surround sound. So what do you need to do when you want to watch a DVD )?
1. Dim the light;
2. Drop the screen;
3. Open the projector;
4. Switch the projector input to the DVD;
5. Set the projector to the wide screen mode;
6. Enable the power amplifier;
7. Set the power amplifier input to a DVD;
8. Set the power amplifier to surround sound;
9. Adjust the amplifier volume to medium;
10. Open the DVD player;
11. Start playing the DVD.
I think I would rather not watch it if I had to make such a hard time watching a DVD. Which of the following operations are exposed?ProblemWhat about it?
1. difficult operations. It is embodied in opening a DVD, disabling a DVD, listening to a CD, or broadcasting.
2. upgrade is troublesome (that is, the coupling degree is too large ). If I want to upgrade the system, I have to learn another operation procedure.
ThenHow to solve the problemWhat about it?
Use appearance mode to create a portal class (or management class) and expose some methods, call these subsystems in these methods (the subsystems here refer to lighting, screen, projector, power amplifier, and DVD ). DetailsCodeVery simple.
Appearance ModeAdvantages:
1. The interface is simplified to facilitate customer use.
2. decoupling between the customer and the sub-system for easy maintenance.
Disadvantages:
1. An additional packaging class may increase complexity and development time, and reduce runtime performance.
Note:
1. The appearance mode simplifies the interface, but this does not mean that the subsystem is completely encapsulated. If necessary, the interfaces of these subsystems can be exposed to customers, which is called advanced functions (or custom functions ).
2. features cannot be added in appearance mode, but some features can be executed in order. For example, you can open a DVD first and then play it again.
3. subsystems are not in one-to-one relationship with appearance, but in many-to-many relationship. A sub-system can have multiple appearances, and a single appearance can call multiple subsystems.
4. The difference between the appearance mode and the adapter mode is not the number of packaged classes, but the intention is different. The adapter mode can also wrap many classes, but its intention is to change the interface to meet the customer's expectations; the appearance mode is to simplify the interface for easy use.