The explanation of bridge mode in "Big Talk design mode":
Mobile phone brand and software are two concepts, different software can be on different phones, different phones can have the same software, both have great variability. If we were to inherit the extension of the mobile phone brand or mobile phone software as a base class, there would undoubtedly be a huge increase in the number of classes and a high degree of coupling, (if you change the brand or add a lot of software changes) the structure of the two methods are as follows:
So to abstract the two two base classes are Phonebrand and Phonesoft, then in the brand class aggregation of a software object's base class will solve the problem of software and mobile phone expansion confusion, so the expansion of the two are relatively flexible, cut short the necessary links between the two, the structure is as follows:
//Bridge.cpp:Defines the entry point for the console application.//#include"stdafx.h"#include<iostream>using namespacestd;classphonesoft{ Public: Virtual voidRun () =0;};classPlayballgame: Publicphonesoft{ Public: voidrun () {cout<<"Playball"<<Endl; }};classAddressList: Publicphonesoft{ Public: voidrun () {cout<<"AddressList"<<Endl; }};classphonebrand{ Public: Virtual voidSetsoft (Phonesoft * p) =0; Virtual voidRun () =0;protected: Phonesoft*Psoft;};classNokia: Publicphonebrand{ Public: voidSetsoft (Phonesoft *p) { This->psoft =p; } voidrun () {cout<<"Nokia:"; This->psoft->run (); }}; classMoto: Publicphonebrand{ Public: voidSetsoft (Phonesoft *p) { This->psoft =p; } voidrun () {cout<<"Moto:"; This->psoft->run (); }};intMainintargcChar*argv[]) {Phonebrand* Pphone =NewMoto; Pphone->setsoft (NewAddressList); Pphone-run (); Pphone->setsoft (Newplayballgame); Pphone-run (); return 0;}
Bridging Mode Bridge