Facade appearance mode (reprinted cnblogs)

Source: Internet
Author: User
Structure of the fa c Ade appearance Mode

Features of this mode:
The client code does not need to care about subsystems. It only needs to care about the interfaces left behind after aggregation and the interfaces for external interaction. The subsystem is the aggregation of other subsystems. In this mode, any changes to the internal subsystem will not affect the changes to the aggregated interfaces. To achieve the decoupling effect.

First, we need to implement three subsystems (wheel, engine, and body ):

Internal class engine // sub-system Engine
{

Public String enginework ()
{

Return "BMW's engine is working ";

}
Public String enginestop ()
{

Return "BMW's engine is stoped ";

}

}

Internal Class Wheel // sub-system wheel
{
Public String wheelcircumrotate ()
{
Return "BMW 'Wheel is circumrotating ";

}

Public String wheelstop ()
{
Return "BMW's wheel is stoped ";

}

}

Internal class body // subsystem body
{

Public wheel [] Wheels = new wheel [4];
Public engine = new engine ();
Public body ()
{

For (INT I = 0; I <wheels. length; I ++)
{
Wheels [I] = new wheel ();
}

}

}

Public class carfacade // aggregation of sub-systems

{
Body = new body ();
Public void run ()
{

Httpcontext. Current. response. Write (body. Engine. enginework ());
For (INT I = 0; I <body. Wheels. length; I ++)
{

Httpcontext. Current. response. Write (body. Wheels [I]. wheelcircumrotate ());

}

}

Public void stop ()
{
Httpcontext. Current. response. Write (body. Engine. enginestop ());
For (INT I = 0; I <body. Wheels. length; I ++)
{

Httpcontext. Current. response. Write (body. Wheels [I]. wheelstop ());

}

}

 

}

The carfacade interface after aggregation is implemented in the foreground

Carfacade Xiao = new carfacade ();
Xiao. Run ();
Xiao. Stop ();

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.