zoukankan      html  css  js  c++  java
  • Facade Pattern

    1.Facade 模式在高层组合封装了子系统的接口,解耦了系统。隐藏了子系统的复杂性,使其更易使用。

    2.Facade 模式结构图

    3.实现

     1 #ifndef _FACADE_H_
     2 #define _FACADE_H_ 
     3 
     4 class Subsystem1
     5 {
     6 public:
     7     Subsystem1();
     8     ~Subsystem1();
     9     void Operation();
    10 protected: 
    11 private:
    12 };
    13 
    14 class Subsystem2
    15 {
    16 public:
    17     Subsystem2();
    18     ~Subsystem2();
    19     void Operation(); 
    20 protected: 
    21 private:
    22 };
    23 
    24 class Facade
    25 {
    26 public:
    27     Facade();
    28     ~Facade();
    29     void OperationWrapper(); 
    30 protected:
    31 private:
    32     Subsystem1* _subs1;
    33     Subsystem2* _subs2;
    34 };
    35 
    36 #endif
    Facade.h
     1 #include "Facade.h" 
     2 #include <iostream>
     3 using namespace std; 
     4 
     5 Subsystem1::Subsystem1()
     6 {
     7 
     8 } 
     9 
    10 Subsystem1::~Subsystem1()
    11 {
    12 
    13 } 
    14 
    15 void Subsystem1::Operation()
    16 {
    17     cout<<"Subsystem1 operation.."<<endl;
    18 }
    19 
    20 Subsystem2::Subsystem2()
    21 {
    22 
    23 } 
    24 
    25 Subsystem2::~Subsystem2()
    26 {
    27 
    28 } 
    29 
    30 void Subsystem2::Operation()
    31 {
    32     cout<<"Subsystem2 operation.."<<endl;
    33 } 
    34 
    35 Facade::Facade()
    36 {
    37     this->_subs1 = new Subsystem1();
    38     this->_subs2 = new Subsystem2();
    39 }
    40 
    41 Facade::~Facade()
    42 {
    43     delete _subs1;
    44     delete _subs2;
    45 }
    46 
    47 void Facade::OperationWrapper()
    48 {
    49     this->_subs1->Operation();
    50     this->_subs2->Operation();
    51 }
    Facade.cpp
     1 #include "Facade.h" 
     2 #include <iostream>
     3 using namespace std; 
     4 
     5 int main(int argc,char* argv[])
     6 {
     7     Facade* f = new Facade();
     8     f->OperationWrapper(); 
     9     return 0;
    10 }
    main.cpp
  • 相关阅读:
    TS流批量下载----------Xamarin开发系列
    TS视频流下载合成
    B站缓存视频音频合并
    ActiveX录音插件
    FZU-2191 完美的数字 简单数论
    COCI2011/2012 破解密文 KMP
    COCI2010/2011 踢踏舞 线段树区间子段和
    [USACO03FALL] 受欢迎的牛-G tarjan缩点
    洛谷 P1967 货车运输 最大生成树+倍增LCA
    洛谷 P1613 跑路 倍增+最短路
  • 原文地址:https://www.cnblogs.com/programmer-wfq/p/4662180.html
Copyright © 2011-2022 走看看