#define __CRT_SECURE_NO_WARNINGS
/*
@作者:莫忘输赢
@时间:
2020/02/22 22:36
@版本:v1
@桥接模式
@作用:
多种角度进行分类,将多种角度进行分离,让他们独立进行变化
*/
#include<string>
#include<vector>
#include<iostream>
//#include <vld.h>
//using namespace std;
//手机软件
class HandsetSoft
{
public:
virtual void run() = 0 ;
};
//游戏软件
class HandsetGame :public HandsetSoft
{
public:
virtual void run( )
{
std::cout << "运行手机游戏" << std::endl;
}
};
//通讯录软件
class HandsetAddressList : public HandsetSoft
{
public:
virtual void run()
{
std::cout << "运行手机通讯录" << std::endl;
}
};
//手机品牌
class HandsetBrand
{
protected:
HandsetSoft *m_soft;
public:
void SetHandsetSoft(HandsetSoft *temp)
{
m_soft = temp;
}
virtual void run() = 0;
};
//M品牌
class HandsetBrandM : public HandsetBrand
{
public:
virtual void run()
{
m_soft->run();
}
};
//N品牌
class HandsetBrandN : public HandsetBrand
{
public:
virtual void run()
{
m_soft->run();
}
};
int main()
{
HandsetBrand *brand;
brand = new HandsetBrandM();
HandsetGame *handsetGame = new HandsetGame();
brand->SetHandsetSoft(handsetGame);
brand->run();
HandsetAddressList *handsetAddressList = new HandsetAddressList();
brand->SetHandsetSoft(handsetAddressList);
brand->run();
delete handsetAddressList;
delete handsetGame;
delete brand;
return 0;
}
设计模式总篇-桥接模式
猜你喜欢
转载自blog.csdn.net/wjl18270365476/article/details/104453004
今日推荐
周排行