My design Tour [5]:facade pattern (OO)

Source: Internet
Author: User
Tags ticket

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

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.