Appearance mode
Intention:
Provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes the system easier to use.
Applicability:
1, in the initial stage of design, should be aware of the different two layers, such as the classic three-tier architecture, you need to consider the data access layer and the business logic layer, the business logic layer and the presentation layer between the layers and layers to establish the appearance.
2, in the development stage, the subsystem is often because of the continuous reconstruction of the evolution and become more and more complex, most of the patterns will also produce a lot of small classes, this is good, but also to external calls their user program has brought difficulties in the use of, with the appearance of the model to provide a simple interface, reduce their dependence.
3, when maintaining a large legacy system, it may be very difficult to maintain and expand the system, but because it contains very important features, new requirements development must depend on it. A look-up class is developed for the new system to provide a clearer and simpler interface for designing rough or highly complex legacy code, allowing the new system to interact with the appearance object, and all the complex work of the façade object interacting with the legacy code.
Uml:
Code implementation:
A restaurant, if there is no waiter, then drinks, cutlery, tissues and so on have to customers to take.
Interaction
With the waiter, then the customer has something to directly find the waiter, this is the embodiment of the appearance pattern.
Interaction
Code:
1#include <iostream>2 using namespacestd;3 4 classgettableware{5 Public:6 Gettableware () {}7 voiddoIt ()8 {9cout<<"Get the cutlery! "<<Endl;Ten } One }; A - classgetdrink{ - Public: the Getdrink () {} - voiddoIt () - { -cout<<"Get the drink! "<<Endl; + } - }; + A classgettissue{ at Public: - gettissue () {} - voiddoIt () - { -cout<<"Get the tissue! "<<Endl; - } in }; - to classwaiter{ + Public: - Waiter () the { *Mpgettableware =NewGettableware; $Mpgetdrink =NewGetdrink;Panax NotoginsengMpgettissue =Newgettissue; - } the +~Waiter () A { the Deletempgettissue; + DeleteMpgettableware; - DeleteMpgetdrink; $ } $ voidMgettableware () - { -Mpgettableware->doIt (); the } - voidMgetdrink ()Wuyi { theMpgetdrink->doIt (); - } Wu voidmgettissue () - { AboutMpgettissue->doIt (); $ } - Public: -gettableware*Mpgettableware; -getdrink*Mpgetdrink; Agettissue*mpgettissue; + }; the - classclient{ $ Public: the Client () the { theMwaiter =NewWaiter; the } -~Client () in { the DeleteMwaiter; the } Aboutwaiter*Mwaiter; the }; the the voidMain () + { - client client; theClient.mwaiter->Mgettableware ();BayiClient.mwaiter->Mgetdrink (); theClient.mwaiter->mgettissue (); the return; -}
Appearance mode (facade) C + + implementation