C # design pattern façade design pattern (façade)

Source: Internet
Author: User

First, façade (façade) mode

External communication with a subsystem must be done through a unified façade (façade) object, which is the façade pattern.

Examples of hospitals

With an example, if the hospital as a subsystem, according to departmental functions, this system can be divided into registered, outpatient, pricing, laboratory, charge, take medicine and so on. It is not easy for a patient to work with these departments, just as a subsystem client deals with the various classes of a subsystem.

First, the patient must be registered first and then outpatient. If a doctor asks for a test, the patient must first pricing and then make a payment before he can go to the laboratory for testing. After the test, go back to the clinic room.

The way to solve this inconvenience is to introduce a façade model. can set up a receptionist's position, by the receptionist is responsible for registration, pricing, payment, take medicine and so on. The receptionist is the embodiment of the façade pattern, with the patient only contacting the receptionist, who is responsible for dealing with the various departments of the hospital.

What is the façade mode

The façade mode requires that the external and internal communication of a subsystem must be performed through a unified façade (façade) object. The façade mode provides a high-level interface that makes the subsystem easier to use.

Like a hospital receptionist, the façade class separates the client from the internal complexity of the subsystem, allowing the client to deal only with façade objects without having to deal with many objects within the subsystem.

Second, the structure of the façade model

The façade mode is the structure pattern of the object. The façade model does not have a generalized class diagram description, and the following illustration shows a schematic object graph of a façade pattern:

In this object graph, there are two roles:

Façade (façade) Role: A method by which a client can invoke this role. This role is aware of the functions and responsibilities of the related (one or more) subsystems. Normally, this role delegates all requests sent from the client to the appropriate subsystem.

subsystem (SUBSYSTEM) Role: You can have one or more subsystems at the same time. Each subsystem is not a separate class, but rather a collection of classes. Each subsystem can be called directly by the client or by a façade role. Subsystems do not know the presence of the façade, for the subsystem, the façade is just another client.

Related Article

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.