码迷,mamicode.com
首页 > 编程语言 > 详细

适配器模式之C++实现

时间:2014-06-25 17:08:14      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   tar   color   

 

#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

适配器模式之C++实现

标签:style   class   blog   code   tar   color   

原文地址:http://www.cnblogs.com/jingmoxukong/p/3806223.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!