Design pattern--Façade mode C + + implementation

Source: Internet
Author: User

Façade mode C + + implementation 1 definition facade

The external interface of a subsystem is required to communicate with its internal communication through a unified interface. The façade mode provides a high-level interface that makes the subsystem easier to view

Note: The façade mode focuses on the unified object, which is the interface that provides an access subsystem, except that the interface does not allow any access to the subsystem's behavior to produce

2 class Diagram

Facade façade role, which is the only channel inside the outside access subsystem

subsystem subsystem role, which can be one or more subsystems at the same time, each subsystem is not a separate class but a collection of classes

3 implementation

Subsystem

Class ClassA

{

Public

void DoSomething ()

{

subsystem business logic

}

};

Class ClassB

{

Public

void DoSomething ()

{

subsystem business logic

}

};

Façade objects

Class facade

{

Private

ClassA A;

ClassB b;

Public

void Dosomethinga ()

{

A.dosomething ();

}

void Dosomethingb ()
{

B.dosomething ();

}

};

4 applications

① Advantages

Reduce system interdependencies

Increased flexibility

Improve security

② Disadvantages

does not conform to the opening and closing principle, closed to the modification, open to expansion. Because changes inside the system need to change the façade

③ Usage Scenarios

Provides an external access interface for a complex module or subsystem

subsystem is relatively independent--external access to the subsystem as long as the black box operation can

Prevention of risk spread by low-level personnel

④ precautions

The number of facades can be greater than one:

To the extent that the façade is too large to tolerate

Subsystems can provide different access paths

Note: The façade does not participate in the logical business within the subsystem---if the subsystem internal logic needs to be changed to the external, so long will be encapsulated, and then to the façade rather than let the façade processing logic

Design pattern--Façade mode C + + implementation

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.