C # Introduction to the design mode

Source: Internet
Author: User

1. In the initial stage of design, we should consciously separate different two layers, for example, considering the establishment of a visual mode between the data access layer, business logic layer, and presentation layer, in this way, a simple and consistent interface can be provided for the subsystem, greatly reducing coupling.

2. In the development phase, the subsystem is very complicated because of not enough reconstruction. Increasing the appearance mode can shield this complexity and provide simple interfaces.

3. Maintain a legacy large system. When the code is difficult to maintain, the appearance mode is also a good choice.

Look at the structure of the appearance mode:

Facade class definition: Provides simple interfaces for high-level SystemsCopy codeThe Code is as follows: class Facade
{
SubSystemOne one;
SubSystemTwo two;
SubSystemThree three;
SubSystemFour four;
Public Facade ()
{
One = new SubSystemOne ();
Two = new SubSystemTwo ();
Three = new SubSystemThree ();
Four = new SubSystemFour ();
}
Public void MethodA ()
{
Console. WriteLine ("MethodA Combination Method ");
One. MethodOne ();
Two. MethodOne ();
}
Public void MethodB ()
{
Console. WriteLine ("MethodB Combination Method ");
Three. MethodOne ();
Four. MethodOne ();
}
}

SubSystemOne class: the underlying system is integrated with simple interfaces by the Facade class.Copy codeThe Code is as follows: class SubSystemOne
{
Public void MethodOne ()
{
Console. WriteLine ("Subsystem Method 1 ");
}
}

Main function call:Copy codeThe Code is as follows: class Program
{
Static void Main (string [] args)
{
Facade facade = new Facade ();
Facade. MethodA ();
Facade. MethodB ();
Console. ReadKey ();
}
}

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.