Simple implementation of Bridge Mode C ++ in Design Mode

Source: Internet
Author: User

The bridge mode is used to separate abstraction and implementation so that both of them can change.

The simple implementation code is as follows:

 

# Include <iostream> using namespace std; class Implementor {public: virtual void Operation () = 0 ;}; class ConcreteImplementorA: public Implementor {public: virtual void Operation () {cout <"execution of specific method to implement A" <endl ;}; class ConcreteImplementorB: public Implementor {public: virtual void Operation () {cout <"execution of specific method to implement B" <endl ;}; class runtime action {protected: Implementor * implementor; public: virtual void SetImplementor (Implemen Tor * implementor) {this-> implementor = implementor;} virtual void Operation () = 0; virtual ~ Failed action () {}}; class refined1_action: public 1_action {public: virtual void Operation () {implementor-> Operation ();} virtual ~ RefinedAbstraction () {if (implementor) delete implementor ;}}; int main () {role action * AB = new RefinedAbstraction (); AB-> SetImplementor (new ConcreteImplementorA ()); AB-> Operation (); delete AB; AB = new refined1_action (); AB-> SetImplementor (new ConcreteImplementorB (); AB-> Operation (); delete AB; return 0 ;}

 

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.