Intent
Define a uniform set of Gao Jie surfaces for a stack of interfaces in the subsystem, making subsystems easier to use.
Introduction
The façade is commonly used in two places, the first of which is to wrap the original program-oriented system using a façade into OO, such as the MFC wrapper Win32 API, and the second is to package the original complex OO system into simpler oo, such as. NET Enterprise The library wraps the. NET Framework again, making it easier for you to use. Net. In addition 3-tier is also the application of a typical façade, the Dal (Data Access Layer) is a façade that allows BLL (Business Logic Layer) to access the data without dealing with ado.net complex mechanisms, just face the DAL.
Sample Code
If we take the MRT to buy tickets, the current ticket-selling machine can only eat copper coins, so have to provide additional money-changing machine, so that passengers will be replaced by copper coins, that is, if a passenger with only paper money and the rapid transit ticket, he must do two steps, first will be replaced by copper coins, and then used to buy tickets.
1/**//*
2 (C) Oomusou 2007 http://oomusou.cnblogs.com
3
4filename:dp_facadepattern1_before.cpp
5compiler:visual C + + 8.0/BCB 6.0/GCC 3.4.2/iso C + +
6description:demo How-to-use façade pattern (before
7release:04/24/2007 1.0
8*/
9#include <iostream>
11using namespace std;
13st Ruct Bill {
-int value;
Bill (int value): value (value) {}
;
18struct Coin {
int valu E
Coin (int value): value (value) {}
21};
23class billtocoinmachine {
24public:
Coin getcoin (Bill Bill) {
-return Coin (a);
} 28};
30class cointoticketmachine {
31public:
GetTicket void (Coin Coin) {
cout << "Get tick ET "<< Endl;
34}
35};
37int Main () {
Billtocoinmachine machine1
Coin Coin = Machine1.getcoin (Bill);
4
1 Cointoticketmachine machine2;
Machine2.gettickeT (coin);
}
Perform the results
Get ticket