#include <iostream>
#include <string>
//#include <afx.h>
#include <vector>
#include <list>
using namespace std;
class HandSoft
{
public:
virtual void Run(){};
};
class HandSetGame:public HandSoft
{
public:
void Run()
{
cout<<"运行手机游戏\n";
}
};
class HandSetAddress:public HandSoft
{
public:
void Run()
{
cout<<"运行手机通讯录\n";
}
};
class HandSetBand
{
protected:
HandSoft * psoft;
public:
HandSetBand()
{
psoft = NULL;
}
void SetHandSetSoft(HandSoft * psoft)
{
if(NULL != this->psoft)
delete this->psoft;
this->psoft=psoft;
}
virtual void Run(){};
~HandSetBand()
{
if(NULL != this->psoft)
delete this->psoft;
}
};
class HandSetBandN:public HandSetBand
{
public:
virtual void Run()
{
cout<<"BandN";
psoft->Run();
}
};
class HandSetBandM:public HandSetBand
{
public:
virtual void Run()
{
cout<<"BandM";
psoft->Run();
}
};
int main()
{
HandSetBand * ab;
ab = new HandSetBandN;
ab->SetHandSetSoft(new HandSetGame);
ab->Run();
ab->SetHandSetSoft(new HandSetGame);
ab->Run();
delete ab;
ab = new HandSetBandM;
ab->SetHandSetSoft(new HandSetGame);
ab->Run();
ab->SetHandSetSoft(new HandSetGame);
ab->Run();
delete ab;
cout<<"\nOK\n";
return 1;
}
#include <string>
//#include <afx.h>
#include <vector>
#include <list>
using namespace std;
class HandSoft
{
public:
virtual void Run(){};
};
class HandSetGame:public HandSoft
{
public:
void Run()
{
cout<<"运行手机游戏\n";
}
};
class HandSetAddress:public HandSoft
{
public:
void Run()
{
cout<<"运行手机通讯录\n";
}
};
class HandSetBand
{
protected:
HandSoft * psoft;
public:
HandSetBand()
{
psoft = NULL;
}
void SetHandSetSoft(HandSoft * psoft)
{
if(NULL != this->psoft)
delete this->psoft;
this->psoft=psoft;
}
virtual void Run(){};
~HandSetBand()
{
if(NULL != this->psoft)
delete this->psoft;
}
};
class HandSetBandN:public HandSetBand
{
public:
virtual void Run()
{
cout<<"BandN";
psoft->Run();
}
};
class HandSetBandM:public HandSetBand
{
public:
virtual void Run()
{
cout<<"BandM";
psoft->Run();
}
};
int main()
{
HandSetBand * ab;
ab = new HandSetBandN;
ab->SetHandSetSoft(new HandSetGame);
ab->Run();
ab->SetHandSetSoft(new HandSetGame);
ab->Run();
delete ab;
ab = new HandSetBandM;
ab->SetHandSetSoft(new HandSetGame);
ab->Run();
ab->SetHandSetSoft(new HandSetGame);
ab->Run();
delete ab;
cout<<"\nOK\n";
return 1;
}