java-design mode (structural type)-"appearance mode"

Source: Internet
Author: User

1. Appearance mode (facade)

Know the principle at least: a class should interact with the other classes as little as possible , making the classes relatively independent and the system functional modules relatively independent.

Definition: Reduce the dependency between classes and classes, just like spring, you can configure relationships between classes and classes into a configuration file .

The appearance pattern is to put the relationship between their classes in a facade class , reducing the coupling between classes and classes, which does not involve interfaces.

2. Illustrations

public class Computer {//Individual parts (classes) Private CPU Cpu=new CPU ();p rivate memory M=new memory ();p rivate disk d=new disk ();p u         Blic static void Main (string[] args) {//TODO auto-generated method stub computer cp=new computer ();         Cp.start (); Cp.shutdown ();}      Computer starts public void start () {Cpu.start ();      M.start ();    D.start ();    SYSTEM.OUT.PRINTLN ("Computer is up and ready");      }//Computer off public void shutdown () {cpu.shutdown ();      M.shutdown ();    D.shutdown ();    SYSTEM.OUT.PRINTLN ("Computer complete shutdown");      }}class CPU {public void start () {System.out.println ("CPU boot ...");      } public void Shutdown () {System.out.println ("CPU off ...");    }}class memory{public void Start () {System.out.println ("Memory start ...");    } public void Shutdown () {System.out.println ("Memory closed ...");    }}class disk{public void Start () {System.out.println ("Hard disk boot ..."); } public void Shutdown () {System.out.println ("hard disk closed ..."); }}

Operation Result:

CPU boot ... Memory boot ... Hard Drive Boot ... CPU off after computer starts ... Memory off ... Hard drive off ...

  

java-design mode (structural type)-"appearance mode"

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: info-contact@alibabacloud.com 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.