add Facade pattern

This commit is contained in:
Jakub Vojvoda
2016-09-16 14:23:30 +02:00
parent c9163d066a
commit a7768c2e9c
2 changed files with 84 additions and 0 deletions

83
facade/Facade.cpp Normal file
View File

@@ -0,0 +1,83 @@
/*
* C++ Design Patterns: Facade
* Author: Jakub Vojvoda [github.com/JakubVojvoda]
* 2016
*
* Source code is licensed under MIT licence
* (for more details see LICENCE)
*
*/
#include <iostream>
/*
* Subsystems
* implement more complex subsystem functionality
* and have no knowledge of the facade
*/
class SubsystemA {
public:
void suboperation() {
std::cout << "Subsystem A method" << std::endl;
// ...
}
// ...
};
class SubsystemB {
public:
void suboperation() {
std::cout << "Subsystem B method" << std::endl;
// ...
}
// ...
};
class SubsystemC {
public:
void suboperation() {
std::cout << "Subsystem C method" << std::endl;
// ...
}
// ...
};
/*
* Facade
* delegates client requests to appropriate subsystem object
* and unified interface that is easier to use
*/
class Facade {
public:
Facade() :
subsystemA(), subsystemB(), subsystemC() {}
void operation1() {
subsystemA->suboperation();
subsystemB->suboperation();
// ...
}
void operation2() {
subsystemC->suboperation();
// ...
}
// ...
private:
SubsystemA *subsystemA;
SubsystemB *subsystemB;
SubsystemC *subsystemC;
// ...
};
int main()
{
Facade *facade = new Facade();
facade->operation1();
facade->operation2();
return 0;
}