An in-depth analysis of bridging patterns of design patterns using code and UML diagrams _c language

Source: Internet
Author: User

Bridging mode is the separation of independence and implementation.
Different manufacturers to produce different products .... Products and manufacturers have this combination of relationships.

On the Code

Copy Code code as follows:

Bridge.cpp: Defines the entry point for a console application.
/************************************************************************/
#include "stdafx.h"
#include <iostream>
using namespace Std;
Class Product
{
Public
Product () {}
Virtual ~product () {}

virtual void make () = 0;
virtual void sell () = 0;
};
Class Producta:public Product
{
Public
ProductA () {}
Virtual ~producta () {}
virtual void make ()
{
cout<< "Producta:make ()" <<endl;
}
virtual void sell ()
{
cout<< "Producta:sell ()" <<endl;
}
};
Class Productb:public Product
{
Public
PRODUCTB () {}
Virtual ~PRODUCTB () {}
virtual void make ()
{
cout<< "Productb:make ()" <<endl;
}
virtual void sell ()
{
cout<< "Productb:sell ()" <<endl;
}
};
Class Corp.
{
Public
Corp (product* Pro)
: M_product (PRO)
{}
Virtual ~corp ()
{
Delete m_product;
}

virtual void process ()
{
M_product->make ();
M_product->sell ();
}
Private
Product *m_product;
};
Class Corpa:public Corp.
{
Public
Corpa (Product * Pro): Corp (pro) {}
Virtual ~corpa () {}
virtual void process ()
{
cout<< "Corpa ():p rocess ()" <<endl;
Corp::p rocess ();
}
};
Class Corpb:public Corp.
{
Public
CORPB (Product * Pro): Corp (pro) {}
Virtual ~CORPB () {}
virtual void process ()
{
cout<< "corpb:process ()" <<endl;
Corp::p rocess ();
}
};
int _tmain (int argc, _tchar* argv[])
{
product* product;
Product = new ProductA;
Corp * CORP;
Corp = new Corpa (product);
Corp->process ();
cout<< "----------" <<endl;
product= new ProductB;
Corp = new CORPB (product);
Corp->process ();
return 0;
}

Production and manufacturers are independent realization, fully give the freedom ....
OK, here we go today .... Continue to study

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.