Design Pattern simple code Facade Pattern (Compiling System)

Source: Internet
Author: User

/*************************************** **************************************** ***************************/
* Author: Yi Yutian (http://blog.csdn.net/dylgsy ). This article can be ressed casually, but please keep this information

* Facade mode:

* The facade mode provides a unified and simple interface for the outside world, so that the customer program can be used conveniently. Hiding complex processing processes

* The facade mode is mainly used to provide convenience for callers. The customer should specify the interface to be used.

* A feature of the facade mode is that interfaces encapsulated by the facade mode have some mixed internal operations (internal operations are completed by the collaboration of many objects ).

* In addition, you can use the facade mode to enable the underlying functions for users familiar with internal operations.
/*************************************** **************************************** ***************************/

/*************************************** **************************************** ***************************/
* Instance:

* Here we will use the example in design patterns. This is an example of a compiler. We use the compiler to specify the path and target of the source file.

* The file path is enough. What the compiler does inside is transparent to us.

* The Compiler may do the following:

* For lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation, we will simulate

* This example only shows the facade mode, so the compilation process of the compiler is simplified.
/*************************************** **************************************** ***************************/

# Include <iostream>
Using namespace STD;

// Scanner
Class cquota
{
Public:
Void scan (char * lpszinput)
{
Cout <"Scanning files:" <lpszinput <Endl;
}
};

// Analyzer
Class cparser
{
Public:
Void parse (char * lpszinput)
{
Cout <"file being analyzed:" <lpszinput <Endl;
}
};

// Code Generator
Class ccodegenerator
{
Public:
Void codegen (char * lpszoutput)
{
Cout <"generating code to file:" <lpszoutput <Endl;
}
};

// Provide a facade (compiler)
Class ccompiler
{
Public:
Void compile (char * lpszinput, char * lpszoutput)
{
_ S. Scan (lpszinput );
_ P. parse (lpszinput );
_ C. codegen (lpszoutput );
}
PRIVATE:
C0000_s;
Cparser _ P;
Ccodegenerator _ C;
};

// Use the compilation system: this system includes a scanner, analyzer, and generator. And provides a facade interface Compiler
Void main ()
{
Ccompiler compiler;
Compiler. Compile ("123.cpp"," 123.exe ");
}
 

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.