Study Notes for head. First design patterns (9)-appearance patterns

Source: Internet
Author: User

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.



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.


1. An additional packaging class may increase complexity and development time, and reduce runtime performance.


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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.