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 ();