Design Pattern: facade Mode

Source: Internet
Author: User

Http://www.35java.com/zhibo/forum.php? MoD = viewthread & tid = 275 & extra = Page % 3d2

If you want to write a webmail program, you already have some developed components (component), such as the SMTP processing class required for webmail development and the fileupload class that allows attachment files to be uploaded, and Web security-related APIs and other related packages.

When you get some ready-made components and intend to use them in your application, you should not directly couple these components to your application. For example:

The above practice will allow your application to be directly coupled with multiple components. This practice is not only highly dependent on components, but also requires you to modify the application itself in the future, or it is difficult to replace the dependent components.

You should define a facade interface, define the business logic in it, such as the method for sending the attachment file, and then combine the components at your hand in an implementation class, make it fulfill your desired business behavior, for example:

As shown in, your application itself does not depend on your components directly, but on an interface. When you want to change the implementation of a business behavior, you only need to modify the implemented class, and the application itself does not need to make any modifications.

The structure of the facade mode is as follows:

The facade mode hides the cooperative behavior between various components and the operation and setting details of the components themselves, which makes it easy to directly operate components, therefore, for program designers who like to pursue and operate in detail, they do not like to use facade to operate the components behind the scenes. Therefore, your facade interface design, it is usually necessary to strike a balance between the component dependency and the supporting Operation of the component.

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.