Resolving design patterns with code and UML diagrams-Bridge pattern

Source: Internet
Author: User

The bridge mode is separated from the implementation mode.

Different manufacturers produce different products .... Products and manufacturers have this combination.

 

 

Code on

[Cpp]
// Bridge. cpp: defines the entry point of the console application.
//
/
//************************************** **********************************/
/* @ Filename Bridge. cpp
@ Author wallwind
@ Createtime
@ Function Bridge Mode
@ Email wochenglin@qq.com
*/
/*************************************** *********************************/
 
 
# 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;
}
Both the production and the manufacturer are independently implemented, fully providing

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.