DesignPattern/08.BridgePattern/2.Code/BridgePattern.h

88 lines
1.1 KiB
C
Raw Normal View History

2019-10-23 14:19:36 +00:00
#ifndef __BRIDGE_PATTERN_H__
#define __BRIDGE_PATTERN_H__
#include <iostream>
#include <string.h>
#include <mutex>
using namespace std;
2021-10-28 13:58:09 +00:00
// 实现类接口Implementor
2019-10-23 14:19:36 +00:00
class Game
{
public:
Game(){}
virtual ~Game(){}
2019-10-23 14:19:36 +00:00
virtual void play() = 0;
private:
};
2021-10-28 13:58:09 +00:00
// 具体实现类GameA
2019-10-23 14:19:36 +00:00
class GameA:public Game
{
public:
GameA(){}
void play(){
2021-10-28 13:58:09 +00:00
printf("Jungle<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϷA\n");
2019-10-23 14:19:36 +00:00
}
};
2021-10-28 13:58:09 +00:00
// 具体实现类GameB
2019-10-23 14:19:36 +00:00
class GameB :public Game
{
public:
GameB(){}
void play(){
2021-10-28 13:58:09 +00:00
printf("Jungle<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϷB\n");
2019-10-23 14:19:36 +00:00
}
};
2021-10-28 13:58:09 +00:00
//抽象类Phone
2019-10-23 14:19:36 +00:00
class Phone
{
public:
Phone(){
}
virtual ~Phone(){}
2021-10-28 13:58:09 +00:00
// Setup game
2019-10-23 14:19:36 +00:00
virtual void setupGame(Game *igame) = 0;
virtual void play() = 0;
private:
Game *game;
};
2021-10-28 13:58:09 +00:00
// 扩充抽象类PhoneA
2019-10-23 14:19:36 +00:00
class PhoneA:public Phone
{
public:
PhoneA(){
}
2021-10-28 13:58:09 +00:00
// Setup game
2019-10-23 14:19:36 +00:00
void setupGame(Game *igame){
this->game = igame;
}
void play(){
this->game->play();
}
private:
Game *game;
};
2021-10-28 13:58:09 +00:00
// 扩充抽象类PhoneB
2019-10-23 14:19:36 +00:00
class PhoneB :public Phone
{
public:
PhoneB(){
}
2021-10-28 13:58:09 +00:00
// Setup game
2019-10-23 14:19:36 +00:00
void setupGame(Game *igame){
this->game = igame;
}
void play(){
this->game->play();
}
private:
Game *game;
};
#endif //__BRIDGE_PATTERN_H__