Design pattern of the façade mode

Source: Internet
Author: User

façade mode definition: Requires that a subsystem's external communication with its internal must be done through a single object. Façade mode provides a high-level interface that makes subsystems easier to use.

Advantages:

1, reduce the interdependence of the system. Outside access does not have to go deep inside the subsystem.

2. Increased flexibility.

3, improve security.

Disadvantages:

The biggest disadvantage of the façade mode is that it does not conform to the opening and shutting principle.

The class diagram is as follows:

The implementation code is as follows:

Subsystem Class ClassA:

Package com.designpatterns.facade;/** * @author WSYW126 * @version May 6, 2016 PM 7:16:45 */public class ClassA {public void D Osomething () {System.out.println ("Cooking");}}

Subsystem class CLASSB:

Package com.designpatterns.facade;/** * @author WSYW126 * @version May 6, 2016 PM 7:16:45 */public class ClassB {public void D Osomething () {System.out.println ("eat");}}
Subsystem Class C:

Package com.designpatterns.facade;/** * @author WSYW126 * @version May 6, 2016 PM 7:16:45 */public class ClassC {public void D Osomething () {System.out.println ("Brush Bowl");}}
External Quondam role Facade class:

Package com.designpatterns.facade;/** * @author WSYW126 * @version May 6, 2016 PM 7:19:14 */public class Facade {ClassA A = NE W ClassA (); ClassB B = new ClassB (); ClassC C = new ClassC ();p ublic void Eat () {a.dosomething (); B.dosomething (); C.dosomething ();}}

Test class:

Package com.designpatterns.facade;/** * @author WSYW126 * @version May 6, 2016 PM 7:20:30 */public class Client {public static void Main (string[] args) {System.out.println ("I want to eat!") "); Facade F = new facade (); F.eat ();}}

This is the façade mode.

References :
The Zen of design pattern

Remark :
Reprint please indicate the source
http://blog.csdn.net/wsyw126/article/details/51334018
by WSYW126

Design pattern of the façade mode

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.