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