适配器模式之C++实现

时间:2014-06-25 17:08:14   收藏:0   阅读:223

 

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;

//Target
class ForeignMovie
{
public:
    virtual void ShowSubtitle() = 0;
};

//中文字幕
class ChineseSubtitle
{
public:
    void ShowChineseSubtitle()
    {
        cout << "显示中文字幕" << endl;
    }
};

//外文电影默认显示外文字幕,如果要显示中文字幕,需要翻译适配
class Translate : public ForeignMovie
{
private:
    ChineseSubtitle *pChineseSubtitle;
public:
    Translate()
    {
        pChineseSubtitle = new ChineseSubtitle;
    }
    
    void ShowSubtitle()
    {
        pChineseSubtitle->ShowChineseSubtitle();
    }
};

int main()
{
    Translate *pTranslate = new Translate;
    pTranslate->ShowSubtitle();
    return 0;
}

 

适配器模式之C++实现,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!