Bridging Mode Bridge

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.