diff --git a/8.BridgePattern/1.Picture/UML实例图.png b/8.BridgePattern/1.Picture/UML实例图.png new file mode 100644 index 0000000..d5cf10d Binary files /dev/null and b/8.BridgePattern/1.Picture/UML实例图.png differ diff --git a/8.BridgePattern/1.Picture/桥接模式UML图.png b/8.BridgePattern/1.Picture/桥接模式UML图.png new file mode 100644 index 0000000..3d84eda Binary files /dev/null and b/8.BridgePattern/1.Picture/桥接模式UML图.png differ diff --git a/8.BridgePattern/1.Picture/桥接模式举例图.png b/8.BridgePattern/1.Picture/桥接模式举例图.png new file mode 100644 index 0000000..9f2a72e Binary files /dev/null and b/8.BridgePattern/1.Picture/桥接模式举例图.png differ diff --git a/8.BridgePattern/2.Code/BridgePattern.h b/8.BridgePattern/2.Code/BridgePattern.h new file mode 100644 index 0000000..0ed6871 --- /dev/null +++ b/8.BridgePattern/2.Code/BridgePattern.h @@ -0,0 +1,86 @@ +#ifndef __BRIDGE_PATTERN_H__ +#define __BRIDGE_PATTERN_H__ + +#include +#include +#include +using namespace std; + +//ʵӿ +class Game +{ +public: + Game(){} + virtual void play() = 0; +private: +}; + +//ʵGameA +class GameA:public Game +{ +public: + GameA(){} + void play(){ + printf("JungleϷA\n"); + } +}; + +//ʵGameB +class GameB :public Game +{ +public: + GameB(){} + void play(){ + printf("JungleϷB\n"); + } +}; + +//Phone +class Phone +{ +public: + Phone(){ + } + //װϷ + virtual void setupGame(Game *igame) = 0; + virtual void play() = 0; +private: + Game *game; +}; + +//PhoneA +class PhoneA:public Phone +{ +public: + PhoneA(){ + } + //װϷ + void setupGame(Game *igame){ + this->game = igame; + } + void play(){ + this->game->play(); + } +private: + Game *game; +}; + +//PhoneB +class PhoneB :public Phone +{ +public: + PhoneB(){ + } + //װϷ + void setupGame(Game *igame){ + this->game = igame; + } + void play(){ + this->game->play(); + } +private: + Game *game; +}; + + +#endif //__BRIDGE_PATTERN_H__ \ No newline at end of file diff --git a/8.BridgePattern/2.Code/main.cpp b/8.BridgePattern/2.Code/main.cpp new file mode 100644 index 0000000..ff36da4 --- /dev/null +++ b/8.BridgePattern/2.Code/main.cpp @@ -0,0 +1,23 @@ +#include +#include "BridgePattern.h" + +int main() +{ + Game *game; + Phone *phone; + + //JunglePhoneAƷƵֻϷA + phone = new PhoneA(); + game = new GameA(); + phone->setupGame(game); + phone->play(); + printf("++++++++++++++++++++++++++++++++++\n"); + + //JungleֻϷB + game = new GameB(); + phone->setupGame(game); + phone->play(); + + system("pause"); + return 0; +} \ No newline at end of file diff --git a/README.md b/README.md index 90975ee..4a86323 100644 --- a/README.md +++ b/README.md @@ -39,4 +39,8 @@ 10.设计模式(十)——适配器模式 -博客地址:https://blog.csdn.net/sinat_21107433/article/details/102656617 \ No newline at end of file +博客地址:https://blog.csdn.net/sinat_21107433/article/details/102656617 + +11.设计模式(十一)——桥接模式 + +博客地址:https://blog.csdn.net/sinat_21107433/article/details/102694306 \ No newline at end of file