The bridge mode is separated from the implementation mode.
Different manufacturers produce different products .... Products and manufacturers have this combination.
Code onCopy codeThe Code is as follows: // Bridge. cpp: defines the entry point of the console application.
/*************************************** *********************************/
# Include "stdafx. h"
# Include <iostream>
Using namespace std;
Class Product
{
Public:
Product (){}
Virtual ~ Product (){}
Virtual void make () = 0;
Virtual void Merge () = 0;
};
Class ProductA: public Product
{
Public:
ProductA (){}
Virtual ~ ProductA (){}
Virtual void make ()
{
Cout <"ProductA: make ()" <endl;
}
Virtual void Merge ()
{
Cout <"ProductA: extract ()" <endl;
}
};
Class ProductB: public Product
{
Public:
ProductB (){}
Virtual ~ ProductB (){}
Virtual void make ()
{
Cout <"ProductB: make ()" <endl;
}
Virtual void Merge ()
{
Cout <"ProductB: extract ()" <endl;
}
};
Class Corp
{
Public:
Corp (Product * pro)
: M_product (pro)
{}
Virtual ~ Corp ()
{
Delete m_product;
}
Virtual void process ()
{
M_product-> make ();
M_product-> values ();
}
Private:
Product * m_product;
};
Class CorpA: public Corp
{
Public:
CorpA (Product * pro): Corp (pro ){}
Virtual ~ CorpA (){}
Virtual void process ()
{
Cout <"CorpA (): process ()" <endl;
Corp: process ();
}
};
Class CorpB: public Corp
{
Public:
CorpB (Product * pro): Corp (pro ){}
Virtual ~ CorpB (){}
Virtual void process ()
{
Cout <"CorpB: process ()" <endl;
Corp: process ();
}
};
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 independently implemented, giving full freedom ....
OK. It's here today .... Continue Learning