zoukankan      html  css  js  c++  java
  • 设计模式——适配器模式(C++实现)

     
     
     
     
     

     1 #include <iostream>
     2 #include <string>
     3 
     4 using namespace std;
     5 
     6 
     7 class STTarget
     8 {
     9 public:
    10         virtual void Request()
    11         {
    12 
    13         }
    14 
    15         virtual ~STTarget()
    16         {
    17 
    18         }
    19 
    20 };
    21 
    22 class STAdaptee
    23 {
    24 public:
    25         void SpecificRequest()
    26         {
    27                 cout<< "STAdaptee..........."<< endl;
    28         }
    29 };
    30 
    31 class STAdapter: public STTarget
    32 {
    33 public:
    34         STAdapter(STAdaptee* pstAdaptee): m_pstAdaptee(pstAdaptee)
    35         {
    36 
    37         }
    38         virtual ~STAdapter()
    39         {
    40                 delete m_pstAdaptee;
    41         }
    42 
    43         virtual void Request()
    44         {
    45                 m_pstAdaptee->SpecificRequest();
    46         }
    47 
    48         STAdaptee* m_pstAdaptee;
    49 };
    50 
    51 int main(int argc, char* argv[])
    52 {
    53         STTarget* pstTarget = new STAdapter(new STAdaptee);
    54 
    55         pstTarget->Request();
    56 
    57         delete pstTarget;
    58 
    59         return 0;
    60 }
    61 ///////////////////////////
    62 [root@ ~/learn_code/design_pattern/14_adapter]$ ./adapter       
    63 STAdaptee...........
  • 相关阅读:
    ACM Red and Black
    ACM Wooden Stricks
    ACM Strange fuction
    ACM pie
    ACM Doing Homework again
    ACM FatMouse' Trade
    ACM 今年暑假不AC
    ACM Ignatius and the Princess II
    一、数组---第三大的数
    一、数组---移动零※※※※※※
  • 原文地址:https://www.cnblogs.com/070412-zwc/p/6864023.html
Copyright © 2011-2022 走看看