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

86 lines
1.0 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;
//ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
class Game
{
public:
Game(){}
virtual void play() = 0;
private:
};
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>GameA
class GameA:public Game
{
public:
GameA(){}
void play(){
printf("Jungle<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϷA\n");
}
};
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>GameB
class GameB :public Game
{
public:
GameB(){}
void play(){
printf("Jungle<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϷB\n");
}
};
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Phone
class Phone
{
public:
Phone(){
}
//<2F><>װ<EFBFBD><D7B0>Ϸ
virtual void setupGame(Game *igame) = 0;
virtual void play() = 0;
private:
Game *game;
};
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PhoneA
class PhoneA:public Phone
{
public:
PhoneA(){
}
//<2F><>װ<EFBFBD><D7B0>Ϸ
void setupGame(Game *igame){
this->game = igame;
}
void play(){
this->game->play();
}
private:
Game *game;
};
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PhoneB
class PhoneB :public Phone
{
public:
PhoneB(){
}
//<2F><>װ<EFBFBD><D7B0>Ϸ
void setupGame(Game *igame){
this->game = igame;
}
void play(){
this->game->play();
}
private:
Game *game;
};
#endif //__BRIDGE_PATTERN_H__