zoukankan      html  css  js  c++  java
  • 8 外观模式

    牛市股票还会亏钱?——外观模式

    外观模式(Facade),又门面模式,为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。

    外观模式C++代码
    1 #include <iostream>
    2 #include <string>
    3
    4  using std::cout;
    5  using std::endl;
    6
    7 //四个子系统的类
    8 class SubSystemOne
    9 {
    10 public:
    11 void MethodOne()
    12 {
    13 cout<<"子系统方法一"<<endl;
    14 }
    15 };
    16
    17 class SubSystemTwo
    18 {
    19 public:
    20 void MethodTwo()
    21 {
    22 cout<<"子系统方法二"<<endl;
    23 }
    24 };
    25
    26 class SubSystemThree
    27 {
    28 public:
    29 void MethodThree()
    30 {
    31 cout<<"子系统方法三"<<endl;
    32 }
    33 };
    34
    35 class SubSystemFour
    36 {
    37 public:
    38 void MethodFour()
    39 {
    40 cout<<"子系统方法四"<<endl;
    41 }
    42 };
    43
    44 //外观类
    45 class Facade
    46 {
    47 public:
    48 Facade()
    49 {
    50 one = new SubSystemOne();
    51 two = new SubSystemTwo();
    52 three = new SubSystemThree();
    53 four = new SubSystemFour();
    54 }
    55 void MethodA()
    56 {
    57 cout<<"方法组A:"<<endl;
    58 one->MethodOne();
    59 two->MethodTwo();
    60 three->MethodThree();
    61 four->MethodFour();
    62 }
    63 void MethodB()
    64 {
    65 cout<<"方法组B:"<<endl;
    66 one->MethodOne();
    67 two->MethodTwo();
    68 four->MethodFour();
    69 }
    70 private:
    71 SubSystemOne* one;
    72 SubSystemTwo* two;
    73 SubSystemThree* three;
    74 SubSystemFour* four;
    75 };
    76
    77 int main()
    78 {
    79 Facade *facade = new Facade();
    80
    81 facade->MethodA();
    82 cout<<endl;
    83 facade->MethodB();
    84
    85 return 0;
    86 }
  • 相关阅读:
    CodeForce 677C
    1A -- Theatre Square
    CodeForce 677B Vanya and Food Processor
    CodeForce 680C Bear and Prime 100
    1B -- Spread sheet
    socket.io 推送
    网站性能测试
    openlayers/// Puppeteer.js
    div 光标处插入内容
    emjoi 表情
  • 原文地址:https://www.cnblogs.com/sifenkesi/p/1736772.html
Copyright © 2011-2022 走看看