-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadaptor mode2.cpp
80 lines (75 loc) · 1.52 KB
/
adaptor mode2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <string>
using namespace std;
class Player
{
protected:
string name;
public:
Player(string strName) { name = strName+ ":"; }
virtual void Attack()=0;
virtual void Defense()=0;
};
class Forwards : public Player
{
public:
Forwards(string strName):Player(strName){}
public:
virtual void Attack()
{
cout<<name<<"Forwards attack"<<endl;
}
virtual void Defense()
{
cout<<name<<"Forwards defense"<<endl;
}
};
//这个中锋是外来的,不是我写的,功能一样,但是接口不一样,怎么办
class Center
{
private:
string name;
public:
Center(string strName)
{name = strName + ":";}
public://这个中锋只懂得ChineseAttach这个方法,不明白Attach的意思
void JingGong()
{
cout<<name<<"中场进攻"<<endl;
}
void FanShou()
{
cout<<name<<"中场防守"<<endl;
}
};
//为中场翻译
class TransLater: public Player
{
private:
Center *player;//指定Center类对象player需要翻译,外来人口啦
public://继承父类的构造函数,同时将外来人口接口实现
TransLater(string strName):Player(strName)
{
player = new Center(strName);
}
virtual void Attack()//将中文转为英文的一般性接口
{
player->JingGong();
}
virtual void Defense()
{
player->FanShou();
}
};
//客户端
int main()
{
Player *Cp=new TransLater("姚明");
Player *Fp = new Forwards("Rose");
Cp->Attack();//这时外来人口就可以和本地人一样使用Attach方法。
Fp->Attack() ;//一样的方法却有两国语言, 这样Rose和姚明都听得懂了
delete(Cp);
delete(Fp);
system("pause");
return 0;
}