C++实现设计模式:Bridge Pattern
来源:互联网 发布:中国软件行业协会aaa 编辑:程序博客网 时间:2024/05/16 18:04
注:为了简要说明,类的成员函数均采用inline。
#ifndef _DRIVE_GAME_H_
#define _DRIVE_GAME_H_
#include "DriveGameImpl.h"
#include <iostream>
using std::cout;
using std::endl;
class DriveGame
{
public:
DriveGame(DriveGameImpl* impl):_impl(impl){}
virtual ~DriveGame(){}
virtual void init()
{
cout<<"Init the game."<<endl;
_impl->display();
_impl->flush();
}
virtual void startGame() = 0
{
//Omit for brief description.
}
private:
DriveGameImpl* _impl;
};
class DriveGame_3D:public DriveGame
{
public:
DriveGame_3D(DriveGameImpl* impl):DriveGame(impl)
{
//Omit for brief description.
}
~DriveGame_3D()
{
//To clear the status of the game.
}
virtual void startGame()
{
init();
cout<<"Start 3D Drive Game."<<endl;
}
private:
//Omit for brief description.
};
class DriveGame_2D:public DriveGame
{
public:
DriveGame_2D(DriveGameImpl* impl):DriveGame(impl)
{
//
}
~DriveGame_2D()
{
//To clear the status of the game.
}
virtual void startGame()
{
init();
cout<<"Start 2D Drive Game."<<endl;
}
private:
//Omit for brief description.
};
#endif
#ifndef _DRIVE_GAME_IMPL_H_
#define _DRIVE_GAME_IMPL_H_
#include <iostream>
using std::cout;
using std::endl;
using std::string;
class DriveGameImpl
{
public:
virtual ~DriveGameImpl(){}
virtual void display()=0{}
virtual void flush()=0{}
};
class LinuxDriveGameImpl:public DriveGameImpl
{
public:
~LinuxDriveGameImpl(){}
void display()
{
cout<<"Linux system: display the game."<<endl;
}
void flush()
{
cout<<"Linux system: flush the game."<<endl;
}
};
class WindowsDriveGameImpl:public DriveGameImpl
{
public:
~WindowsDriveGameImpl(){}
void display()
{
cout<<"windows system: display the game."<<endl;
}
void flush()
{
cout<<"windows system: flush the game."<<endl;
}
};
#endif
#include <iostream>
#include "DriveGame.h"
#include "DriveGameImpl.h"
using std::cout;
using std::endl;
using std::string;
int main()
{
DriveGameImpl* linuxGameImpl = new LinuxDriveGameImpl();
DriveGame* game_2D_Linux = new DriveGame_2D(linuxGameImpl);
game_2D_Linux->startGame();
system("PAUSE");
}
- 设计模式实现(七): Bridge Pattern
- C++实现设计模式:Bridge Pattern
- 乐在其中设计模式(C#) - 桥接模式(Bridge Pattern)
- 设计模式之Bridge Pattern
- 设计模式之Bridge Pattern
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式--桥接模式(bridge pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-----桥接模式(Bridge Pattern)
- 设计模式-桥接模式(Bridge Pattern)
- 设计模式 桥接模式(Bridge Pattern)
- 快速处理U盘故障的4个办法【mfxp】
- [XML ]SelectNodes的用法
- 虚拟光驱无法加载镜像
- 自定义Navigationbaritem
- C/C++ 如果函数的参数是一个指针 可以用该指针去申请动态内存吗?
- C++实现设计模式:Bridge Pattern
- u-boot 的调试方法
- windows下python安装
- 面向对象(C++)
- poj3974(Manacher算法)
- C++实现设计模式:Builder Pattern
- 程序员面试题精选100题 详解
- hdu 1395 2^x mod n = 1 欧拉定理(当然可以直接暴力)
- C++实现设计模式:Decorator Pattern