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