zoukankan      html  css  js  c++  java
  • c++设计模式:适配器模式

    1.主要思想:将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。

          对于不同的客户我们可以这样使用适配器模式。

    2.实现方法:

    #include<iostream>
    using namespace std;
     
    // "ITarget"
    class Target
    {
    public:
        // Methods
        virtual void Request(){};
    };
     
    // "Adaptee"
    class Adaptee
    {
    public:
        // Methods
        void SpecificRequest()
        {
            cout<<"Called SpecificRequest()"<<endl;
        }
    };
     
    // "Adapter"
    class Adapter : public Adaptee, public Target
    {
    public:
        // Implements ITarget interface
        void Request()
        {
            // Possibly do some data manipulation
            // and then call SpecificRequest  
            this->SpecificRequest();
        }
    };
     
     
    int main()
    {
        // Create adapter and place a request
        Target *t = new Adapter();
        t->Request();
     
        return 0;
    
    }
  • 相关阅读:
    markdown文件的基本常用编写语法
    ajax练习习题一弹窗查看
    jQuery练习二球队移动
    jQuery Ajax
    jQuery练习一好友列表变色
    jq
    jQuery基础知识
    php pod
    php常用代码(一)
    php多维数组化一维数组
  • 原文地址:https://www.cnblogs.com/mcy0808/p/10833107.html
Copyright © 2011-2022 走看看