添加桥接模式使用方法

master
a7458969 2020-05-20 20:24:38 +08:00
parent ad50d3fc8f
commit 9a8f818518
2 changed files with 43 additions and 1 deletions

View File

@ -16,11 +16,14 @@ class Adaptee{
template<typename T>
class Bridgeable{
public:
Bridgeable(){
}
Bridgeable(T *dat){
mBridgeData = dat;
}
private:
protected:
T *mBridgeData;
};

View File

@ -3,6 +3,39 @@
//
#include "factory.hpp"
#include <iostream>
#include "adapter.hpp"
class Player{
public:
virtual void Play(){
return ;
}
};
class MP3Player :public Player{
void Play(){
std::cout<<"mp3 playing"<<std::endl;
return ;
}
};
class MP4Player :public Player{
void Play(){
std::cout<<"mp4 playing"<<std::endl;
return ;
}
};
class BridgeTest :public Bridgeable<Player>{
public:
BridgeTest(Player *mPlayer) {
this->mBridgeData = mPlayer;
}
void Play(){
this->mBridgeData->Play();
}
private:
BridgeTest(){
}
};
using namespace std;
class Product :public CloneAble<Product>{
public:
@ -30,6 +63,12 @@ private:
char mAttribute2;
};
int main(){
BridgeTest br(new MP3Player);
BridgeTest br1(new MP4Player);
br.Play();
br1.Play();
Product *z = new Product;
z->SetAttr1(-11);
z->SetAttr2('c');