Reading Notes 10: appearance

Source: Internet
Author: User

1. Concepts

Provides a consistent interface for a group of interfaces in the subsystem. This mode defines a high-level interface, which makes the subsystem easier to use.

2. Model

Public class modulara {public void modularamethod () {console. writeline ("A module method. ") ;}} Public class modularb {public void modularbmethod () {console. writeline (" B module method. ") ;}} Public class modularc {public void modularcmethod () {console. writeline (" C module method. ") ;}} Public class facade {private modulara MDA; private modularb MDB; private modularc MDC; Public facade () {MDA = new modulara (); MDB = new modularb (); MDC = new modularc ();} public void facademethod () // This method is responsible for external contact {MDA. modularamethod (); MDB. modularbmethod (); MDC. modularcmethod ();}}

Client

// If you do not need the appearance mode, the client will call modulara, modularb, and modularc respectively, and the coupling will be strong. // Modulara MDA = new modulara (); // modularb MDB = new modularb (); // modularc MDC = new modularc (); // MDA. modularamethod (); // MDB. modularbmethod (); // MDC. modularcmethod (); // use the appearance mode. The client only cares about the facade method, and the sum of the methods is related to this class, reducing coupling. Facade FD = new facade (); FD. facademethod (); console. Readline ();

Result

In fact, this mode is often used when writing code. Sometimes, when writing a separate function module, there is such a class that is responsible for communicating with the outside world and accepting input parameters, it is also responsible for outgoing results. external users do not need to care about how the module is implemented. They often reference this class to input some values, and the class then transmits the results. As for how to implement the function, this module is involved. Therefore, the contact between this module and the outside world is reduced. If the internal algorithm of this module does not affect the operation of other modules, the result is incorrect. In addition, I usually write a separate module to write all the public classes in it in addition to the classes to interact with the outside world as internal, forcing the outside to access internal details.

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.