桥接模式

#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值