mirror of
https://github.com/JakubVojvoda/design-patterns-cpp.git
synced 2025-12-17 12:54:36 +03:00
code refactoring: fix memory leaks, code style, etc.
This commit is contained in:
@@ -15,27 +15,33 @@
|
||||
* implement more complex subsystem functionality
|
||||
* and have no knowledge of the facade
|
||||
*/
|
||||
class SubsystemA {
|
||||
class SubsystemA
|
||||
{
|
||||
public:
|
||||
void suboperation() {
|
||||
void suboperation()
|
||||
{
|
||||
std::cout << "Subsystem A method" << std::endl;
|
||||
// ...
|
||||
}
|
||||
// ...
|
||||
};
|
||||
|
||||
class SubsystemB {
|
||||
class SubsystemB
|
||||
{
|
||||
public:
|
||||
void suboperation() {
|
||||
void suboperation()
|
||||
{
|
||||
std::cout << "Subsystem B method" << std::endl;
|
||||
// ...
|
||||
}
|
||||
// ...
|
||||
};
|
||||
|
||||
class SubsystemC {
|
||||
class SubsystemC
|
||||
{
|
||||
public:
|
||||
void suboperation() {
|
||||
void suboperation()
|
||||
{
|
||||
std::cout << "Subsystem C method" << std::endl;
|
||||
// ...
|
||||
}
|
||||
@@ -47,24 +53,25 @@ public:
|
||||
* delegates client requests to appropriate subsystem object
|
||||
* and unified interface that is easier to use
|
||||
*/
|
||||
class Facade {
|
||||
class Facade
|
||||
{
|
||||
public:
|
||||
Facade() :
|
||||
subsystemA(), subsystemB(), subsystemC() {}
|
||||
|
||||
void operation1() {
|
||||
Facade() : subsystemA(), subsystemB(), subsystemC() {}
|
||||
|
||||
void operation1()
|
||||
{
|
||||
subsystemA->suboperation();
|
||||
subsystemB->suboperation();
|
||||
// ...
|
||||
}
|
||||
|
||||
void operation2() {
|
||||
|
||||
void operation2()
|
||||
{
|
||||
subsystemC->suboperation();
|
||||
// ...
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
|
||||
private:
|
||||
SubsystemA *subsystemA;
|
||||
SubsystemB *subsystemB;
|
||||
@@ -76,8 +83,10 @@ private:
|
||||
int main()
|
||||
{
|
||||
Facade *facade = new Facade();
|
||||
|
||||
facade->operation1();
|
||||
facade->operation2();
|
||||
|
||||
delete facade;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user