Appearance patterns of structural patterns

Source: Internet
Author: User

Overview

In appearance mode, the external and internal communication of a subsystem is carried out through a unified appearance class, which separates the customer class from the internal complexity of the subsystem, making the customer class only needs to deal with the appearance role, without having to deal with many objects inside the subsystem

Defined

Provides a unified portal for a set of interfaces in a subsystem. The appearance pattern defines a high-level interface that makes the subsystem easier to use

Realize

Subsystem

    /// <summary>    ///Registered account Class/// </summary>     Public classRegistaccount {/// <summary>        ///Registration Method/// </summary>         Public voidRegister () {Console.WriteLine ("Account Registration Successful ..."); }    }
 /// <SUMMARY>  ///  shopping  /// </summary>  public  class  Span style= "color: #000000;" > shopping { public  void   shop () {Console.WriteLine (   Shopping items ...   "        ); }    }
    /// <summary>    /// Payment Class     /// </summary>     Public class Pay    {        publicvoid  Paymoney ()        {            Console.WriteLine (" Payment Success ... " );        }    }

Appearance class

    /// <summary>    ///Appearance class/// </summary>     Public classShoppingfacade {PrivatePay pay ; Privateshopping Shopping; PrivateRegistaccount regist;  PublicShoppingfacade (registaccount regist, shopping shopping, pay pay) { This. Pay =Pay ;  This. Shopping =Shopping;  This. regist =regist; }         Public voidBuy () {regist.            Register (); Shopping.            Shop (); Pay.        Paymoney (); }    }

Client

    classProgram {Static voidMain (string[] args) {            varRegist =NewRegistaccount (); varShopping =Newshopping (); varPay =NewPay (); //provides external access through the appearance class, simplifying the way clients accessShoppingfacade FAC =NewShoppingfacade (regist, shopping, pay); Fac.            Buy ();        Console.ReadLine (); }    }

Summarize

Advantages

1, it shields the subsystem components to the client, reduces the number of objects that the client needs to process, and makes the subsystem easier to use. By introducing the appearance pattern, the client code becomes very simple, with very few objects associated with it.

2, it realizes the subsystem and the client loose coupling relationship, which makes the subsystem changes will not affect the client calling it, only need to adjust the appearance of the class.

3, the modification of one subsystem has no effect on other subsystems, and the internal changes of the subsystem will not affect the appearance object.

Disadvantages

1, the client can not be very well restricted to use the subsystem class, if the client Access subsystem classes to do too many restrictions reduce variability and flexibility.

2, if the design is inappropriate, adding new subsystems may need to modify the appearance of the source code of the class, contrary to the open and closed principle.

Appearance patterns of structural patterns

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.