Facade.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <stdio.h>
  2. /*
  3. * C++ Design Patterns: FACADE
  4. * http://www.plantuml.com/plantuml/uml/RP1DJiCm48NtFiMecwv2HDjL5LajXUxefbnWuaofXLqRZus847TXsPuZ5oC_WAYKMVbzCqzlnYkE66AoHkHJsAutw_i7cEQYBMMG6RQei2Bu4901S2gvvaZszbhEhkNyMYx4fn0UrGi-4qmspdf3xp3q9b0KErUHb5r4MqFg_Yze3Cx6u7m43j57NH6GzR46IxQam4Byd9Lbyb_MA9sDqlaeNGXnSf406NR3vaKf2-MC2ylWQZHt9f4Sd4NUSrdafVmTVQezBJi0-nYIYYcWwNkFoA-9m22euVjqR2wG0KL89trmmMfksrDKgZbpRsc-e286TecpRhlcR5k9RwHQ2m5w7vmwKZ_BsdgZ3xgvq8sWKmNT5MBLlf8rtm00
  5. *
  6. */
  7. #include <iostream>
  8. class SubSystem1 {
  9. public:
  10. void suboperation() {
  11. std::cout << "Simplified SubSystem1 operation" << std::endl;
  12. }
  13. };
  14. class SubSystem2 {
  15. public:
  16. void suboperation() {
  17. std::cout << "Simplified SubSystem2 operation" << std::endl;
  18. }
  19. };
  20. class SubSystem3 {
  21. public:
  22. void suboperation() {
  23. std::cout << "Simplified SubSystem3 operation" << std::endl;
  24. }
  25. };
  26. class SubSystem4 {
  27. public:
  28. void suboperation() {
  29. std::cout << "Simplified SubSystem4 operation" << std::endl;
  30. }
  31. };
  32. class Facade {
  33. public:
  34. Facade() {
  35. std::cout << "Constructor Facade" << std::endl;
  36. subsystem1 = new SubSystem1();
  37. subsystem2 = new SubSystem2();
  38. subsystem3 = new SubSystem3();
  39. subsystem4 = new SubSystem4();
  40. }
  41. ~Facade() {
  42. if (subsystem1) {
  43. delete subsystem1;
  44. }
  45. if (subsystem2) {
  46. delete subsystem2;
  47. }
  48. }
  49. void operationWrapper() {
  50. std::cout << "begin operationWrapper Facade" << std::endl;
  51. subsystem1->suboperation();
  52. subsystem2->suboperation();
  53. subsystem3->suboperation();
  54. subsystem4->suboperation();
  55. std::cout << "end operationWrapper Facade" << std::endl;
  56. }
  57. private:
  58. SubSystem1 *subsystem1;
  59. SubSystem2 *subsystem2;
  60. SubSystem3 *subsystem3;
  61. SubSystem4 *subsystem4;
  62. };
  63. int main() {
  64. Facade facade;
  65. facade.operationWrapper();
  66. }