Design Mode note 10 (appearance Mode)

Source: Internet
Author: User

Appearance Mode

The appearance mode provides an integrated interface for a series of subsystem related interfaces, thus reducing the call cost of the customer class for these interfaces.

Recently, the boss of the lab was very depressed because the female secretary was too tired to be hospitalized. In the past, the boss had to do what the Secretary could do.

This is why our lab is boring recently:

Class meetingroom {public Boolean Booking () {return true;} public void prepare () {}public void start () {}} class message {public void policicate (string name) {}} class printer {public void print (string content, int copies) {}} class devices {public void PC () {} public void projector () {}} public class facade {public static void main (string [] ARGs) {meetingroom mr = new meetingroom (); devices d = new devices (); printer P = new printer (); message m = new message (); // book a meeting room mr. booking (); // mr. prepare (); // print the data p. print ("this is a file", 20); // prepare the computer D. PC (); // prepare the projector D. projector (); // notify attendees of the meeting. notificate ("Li Abao"); M. notificate ("Marketing Manager"); M. notificate ("Finance Department Manager"); M. notificate ("orcs plant manager"); Mr. start (); // start the meeting }}

Because the secretary is not there, the boss must do so many steps to get started. This is something that no boss can do, and the boss will not focus on so many different objects, so the boss needs a female secretary to support the facade:

Class nvmishu {Private Static nvmishu mishu; Private Static final object o = new object (); Private nvmishu () {} public static nvmishu getinstance () {If (mishu = NULL) {synchronized (o) {If (mishu = NULL) {mishu = new nvmishu () ;}} return mishu;} public void meeting () {// the process required for these meetings is the meetingroom mr = new meetingroom (); devices d = new devices (); printer P = new printer (); message M = new message (); // book a meeting room mr. booking (); // mr. prepare (); // print the data p. print ("this is a file", 20); // prepare the computer D. PC (); // prepare the projector D. projector (); // notify attendees of the meeting. notificate ("Li Abao"); M. notificate ("Marketing Manager"); M. notificate ("Finance Department Manager"); M. notificate ("orcs plant manager"); Mr. start (); // start meeting} public class facade {public static void main (string [] ARGs) {// The boss only needs to focus on the female secretary, instead of calling different interfaces of different objects. getinstance (). meeting ();}}

With the female secretary, the elders do not need to deal with so many different objects. Instead, they only need to focus on the subject of the female secretary (why is it so serious, I have to declare that I am an upright programmer.) The Boss customer class only needs to study the interface of the female secretary, and does not need to know how other objects work.

Differences between the modifier mode, adapter mode, and appearance Mode

The above three modes are often confused, generally speaking:

The modifier mode extends the new interface without changing the interface of the original object.For ease of use by the client, for example, inputstream and datainputstream are in the decorator mode. datainputstream has both the read interface of inputstream and extends some reading character methods such as readboolean.

InputStream is = null;DataInputStream dis = new DataInputStream(is);dis.readBoolean();

The adapter mode changes the interface of the original object to adapt it to new requirements.That is, the call of the new customer class. For example, inputstream and reader are in the adapter mode.

The appearance mode simplifies interface calls, so that multiple related interfaces have a unified interface call..

 

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.