/*************************************** **************************************** ***************************/
* 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 ");
}