#include <QCoreApplication>
#include<qdebug.h>
//运动员 有攻击和防守两种动作
class player
{
public:
player() {}
~player() {}
public:
QString name;
public:
virtual void attach() = 0;
virtual void defind() = 0;
};
class Forward : public player //前锋
{
public:
Forward( QString name)
{
this->name = name;
}
~Forward() {}
public:
void attach()
{
qDebug() << name << "attach" <<endl;
}
void defind()
{
qDebug() << name << "defind" <<endl;
}
};
class Defender :public player //后卫
{
public:
Defender( QString name )
{
this->name = name;
}
~Defender() {}
public:
void attach()
{
qDebug() << name << "attach" <<endl;
}
void defind()
{
qDebug() << name << "defind" <<endl;
}
};
//外籍球员
class waiji
{
public:
waiji(){}
~waiji(){}
public:
QString name;
public:
void setname( QString wainame ){ name = wainame; }
void gongji()
{
qDebug()<< name<< "gongji"<<endl;
}
void fangshou()
{
qDebug()<<name <<"fangshou"<<endl;
}
};
//针对外籍球员的翻译 适配器
class adapter :public player
{
public:
adapter( QString name )
{
wj.setname( name );
}
~adapter(){}
private:
waiji wj;
public:
void attach()
{
wj.gongji();
}
void defind()
{
wj.fangshou();
}
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
player * pl = new adapter( "yaoming" );
pl->defind();
return a.exec();
}