Bridge pattern (Bridging mode)

Source: Internet
Author: User

/*abstraction.h*/#ifndef Abstraction_h#define abstraction_hClass Abstractionimp;class abstraction{ Public:Virtual~Abstraction();Virtual voidOperation () =0;protected:Abstraction();Private:};class refinedabstraction: Publicabstraction{ Public:refinedabstraction(Abstractionimp *imp); ~refinedavstraction ();voidOperation ();protected:Private: Abstractionimp *imp_;};#endif 
/*Abstraction.cpp*/#include "Abstraction.h"#include "AbstractionImp.h"#include <iostream>Abstraction::Abstraction(){}Abstraction::~Abstraction(){}RefinedAbstraction::RefinedAbstraction(AbstractionImp *imp){    imp_=imp;}RefinedAbstraction::~RefinedAbstraction(){}void RefinedAbstraction::Operation(){    imp_->Operation();}
/*abstractionimp.h*/#ifndef Abstractionimp_h#define abstractionimp_hClass abstractionimp{ Public:Virtual~Abstractionimp();Virtual voidOperation () =0;protected:Abstractionimp();Private:};class Concreteabstractionimpa: Publicabstractionimp{ Public:Concreteabstractionimpa(); ~concreteabstractionimpa ();Virtual voidOperation ();protected:Private:};class CONCRETEABSTRACTIONIMPB: Publicabstractionimp{ Public:CONCRETEABSTRACTIONIMPB(); ~CONCRETEABSTRACTIONIMPB ();Virtual voidOperation ();protected:Private:};#endif 
/*abstractionimp.cpp*/#include"Abstractionimp. h"Abstractionimp:: Abstractionimp (){}Abstractionimp::~Abstractionimp(){}void Abstractionimp:: Operation (){  std::cout<<"Abstractionimp ..."<<std::endl;} Concreteabstractionimpa:: Concreteabstractionimpa (){}Concreteabstractionimpa::~Concreteabstractionimpa(){}void Concreteabstractionimpa:: Operation (){  std::cout<<"Concreteabstractionimpa ..."<<std::endl ; }CONCRETEABSTRACTIONIMPB:: CONCRETEABSTRACTIONIMPB (){}CONCRETEABSTRACTIONIMPB::~CONCRETEABSTRACTIONIMPB(){}void CONCRETEABSTRACTIONIMPB:: Operation (){  std::cout<<"CONCRETEABSTRACTIONIMPB ..."<<std::endl ; }
/*main.cpp*/#include "Abstraction.h"#include "AbstracionImp.h"int main(){    AbstractionImp *imp=new ConcreteAbstractionImpA();    Abstraction *abs=new RefinedAbstraction(imp);    abs->Operation();    return0;}

Bridge pattern (Bridging mode)

Related Article

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.