适配器模式之C++实现

 

#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;
}

 

你可能感兴趣的:(适配器模式)