According to Gang Of Four intent of Facade Design pattern is to Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
SAMPLE CODE:
#include <iostream>
using namespace std;
class PreprocessorSystem {
public:
void doPreprocess()
{
cout << "--->Program In Preprocessing Stage" << endl;
}
};
class CompilerSystem {
public:
void doCompile()
{
cout << "--->Program In Compile Stage" << endl;
}
};
class AssemblerSystem {
public:
void doAssembly()
{
cout << "--->Program in Assembling Stage" << endl;
}
};
class LinkerSystem {
public:
void doLinking()
{
cout << "--->Program In Linking Stage" << endl;
}
};
class CompilerFacade {
private:
PreprocessorSystem preprocessor;
CompilerSystem compiler;
AssemblerSystem assembler;
LinkerSystem linker;
public:
void Compile(string programName)
{
cout << programName << " Compliation Started" << endl;
preprocessor.doPreprocess();
compiler.doCompile();
assembler.doAssembly();
linker.doLinking();
cout << programName << " Compilation Finished" << endl;
}
};
int main()
{
CompilerFacade clientCompiler;
clientCompiler.Compile("MYPROGRAM.cpp");
return 0;
}
OUTPUT:
MYPROGRAM.cpp Compliation Started
--->Program In Preprocessing Stage
--->Program In Compile Stage
--->Program in Assembling Stage
--->Program In Linking Stage
MYPROGRAM.cpp Compilation Finished
INDEX - OTHER DESIGN PATTERNS
SAMPLE CODE:
#include <iostream>
using namespace std;
class PreprocessorSystem {
public:
void doPreprocess()
{
cout << "--->Program In Preprocessing Stage" << endl;
}
};
class CompilerSystem {
public:
void doCompile()
{
cout << "--->Program In Compile Stage" << endl;
}
};
class AssemblerSystem {
public:
void doAssembly()
{
cout << "--->Program in Assembling Stage" << endl;
}
};
class LinkerSystem {
public:
void doLinking()
{
cout << "--->Program In Linking Stage" << endl;
}
};
class CompilerFacade {
private:
PreprocessorSystem preprocessor;
CompilerSystem compiler;
AssemblerSystem assembler;
LinkerSystem linker;
public:
void Compile(string programName)
{
cout << programName << " Compliation Started" << endl;
preprocessor.doPreprocess();
compiler.doCompile();
assembler.doAssembly();
linker.doLinking();
cout << programName << " Compilation Finished" << endl;
}
};
int main()
{
CompilerFacade clientCompiler;
clientCompiler.Compile("MYPROGRAM.cpp");
return 0;
}
OUTPUT:
MYPROGRAM.cpp Compliation Started
--->Program In Preprocessing Stage
--->Program In Compile Stage
--->Program in Assembling Stage
--->Program In Linking Stage
MYPROGRAM.cpp Compilation Finished
INDEX - OTHER DESIGN PATTERNS
No comments:
Post a Comment