Design Mode-fast-appearance Mode]

Source: Internet
Author: User

[Appearance Mode Application Scenario example]

For example, if you are playing the "need for speed" game, you only need to wait for a countdown to 0 and rush to the first place at the fastest speed, however, gamers have no idea what to do before they rush out, such as downgrading, clutch, fuel tank detection, and adjusting the direction, encapsulate these micro-operations into an interface, that is, the appearance mode. In web development, the MVC layered architecture is a typical appearance mode. Each layer hides the specific content of the operation and retains an interface for the upper layer to call.

[Appearance mode description]

Type: Structure Mode

Provides a consistent interface for a group of interfaces in the subsystem.

[Appearance mode UML diagram]

[Appearance mode-Java code implementation]

Create a racing car:

Package car_package;

Public class car {

Public void start (){

System. Out. println ("car started ");


Public void check_stop (){

System. Out. println ("Brake check ");


Public void check_box (){

System. Out. println ("Check tank ");


Public void check_console (){

System. Out. println ("check whether the dashboard is abnormal ");



Appearance of the new racing car operation:

Package car_facade;


Public class car_facade_imple {

Public void car_go_go (CAR car_ref ){

Car_ref.check_box ();

Car_ref.check_console ();

Car_ref.check_stop ();

Car_ref.start ();



Create a client running class:

Package run_main;

Import car_facade.car_facade_imple;

Public class run_main {

Public static void main (string [] ARGs ){

Car_facade_imple car_facade_imple_ref = new car_facade_imple ();

Car_facade_imple_ref.car_go_go (new car ());



The program running result is as follows:

Check fuel tank

Check whether the dashboard is abnormal.

Brake check

Car started

It's easy. encapsulate a sub-operation with an external interface, and then call this interface to call those very complex micro-operations.

[Appearance mode-Java code implementation of myeclipse6 project]

Sample facade code: Click

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.