Design Mode notes-facade Mode

Source: Internet
Author: User

Facade: provides a consistent interface for a group of interfaces in the subsystem. This mode defines a high-level interface, which makes the subsystem easier to use.
Mode description:
SubSystem (SubSystem)
Responsible for handling complex logic processing. Do not deal with customers directly.
Facade)
Interacts with subsystems and provides easy-to-use functions or interfaces to customers.
Client)
Interact with the subsystem through the facade, without the need to care about the details of the subsystem.
UML class diagram:

Basic code for facade mode:
[Cpp]
/*************************************** *****************************
Filename: Facade. h
Created: 2012-09-28
Author: firehood
 
Purpose: The Design Pattern of firehood-Facade Pattern
**************************************** *****************************/
# Pragma once
# Include <iostream>
Using namespace std;
 
Class sub‑ema
{
Public:
Subscribe EMA (void ){}
~ Subscribe EMA (void ){}
Void Operate1 (void)
{
Cout <"subreceivema: Operation 1" <endl;
}
Void Operate2 (void)
{
Cout <"subreceivema: Operation 2" <endl;
}
};
 
Class SubSystemB
{
Public:
SubSystemB (void ){}
~ SubSystemB (void ){}
Void Operate1 (void)
{
Cout <"SubSystemB: Operation 1" <endl;
}
Void Operate2 (void)
{
Cout <"SubSystemB: Operation 2" <endl;
}
};
 
Class SubSystemC
{
Public:
Subscribe EMC (void ){}
~ Subscribe EMC (void ){}
Void Operate1 (void)
{
Cout <"sub‑emc: Operation 1" <endl;
}
Void Operate2 (void)
{
Cout <"subreceivemc: Operation 2" <endl;
}
};
 
Class Facade
{
Public:
Facade (void ){}
Virtual ~ Facade (void ){}
Void MethodA (void)
{
Cout <"method A:" <endl;
M_SubSystemA.Operate1 ();
M_SubSystemB.Operate2 ();
M_SubSystemC.Operate2 ();
}
Void MethodB (void)
{
Cout <"method B:" <endl;
M_SubSystemA.Operate1 ();
M_SubSystemB.Operate1 ();
M_SubSystemC.Operate1 ();
}
Private:
Sub‑ema m_sub‑ema;
SubSystemB m_SubSystemB;
Subscribe EMC m_subscribe EMC;
};

Client call code:
[Cpp]
# Include "Facade. h"
# Include <iostream>
Using namespace std;
 
Int main (int argc, char * argv [])
{
Cout <"************************************ * "<endl;
Cout <"firehood learning design model-facade model" <endl;
Cout <"************************************ * "<endl;

Facade facade;
Facade. MethodA ();
Facade. MethodB ();
 
System ("pause ");
Return 0;
}

Running result:
*************************************
Firehood learning design model-facade Model
*************************************
Method:
Sub‑ema: Operation 1
SubSystemB: Operation 2
Subscribe EMC: Operation 2
Method B:
Sub‑ema: Operation 1
SubSystemB: Operation 1
Subscribe EMC: Operation 1
 

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.