添加桥接模式使用方法
parent
ad50d3fc8f
commit
9a8f818518
|
@ -16,11 +16,14 @@ class Adaptee{
|
|||
template<typename T>
|
||||
class Bridgeable{
|
||||
public:
|
||||
Bridgeable(){
|
||||
|
||||
}
|
||||
Bridgeable(T *dat){
|
||||
mBridgeData = dat;
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
T *mBridgeData;
|
||||
|
||||
};
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue