C # appearance

Source: Internet
Author: User

IronMan appearance

 

Next, I wrote the "plot" of the content of the observer, but it does not matter if I have never seen any friends. There is a link between the length, but it does not affect much.

Requirements:

It provides various support for the "military plant" and produces a variety of "IronMan", because "IronMan" is intelligent and has a "general control center ", it is used to use the functions of each component and other functions. The "general control center" is also the UI that is displayed in front of the user when the user is dressed.

Now we have a problem. When "IronMan" is dressed and started, "general control" will make "IronMan" parts automatically self-check, after the self-check is completed, the self-check result should be displayed on the UI. Of course, the order of self-check can be fixed or not fixed, in the end, all parts are returned for self-check.

Suppose the basic structure:

 

1 public class Component1 2 {3 public void Component1Inspection () 4 {5 // Part 1 self-check 6} 7} 8 public class Component2 9 {10 public void Component2Inspection () 11 {12 // Part 2 self-check 13} 14} 15 public class Component316 {17 public void Component3Inspection () 18 {19 // Part 3 self-check 20} 21}

Assume that there are still several parts, which must be self-checked one by one according to the normal state. In this case, the code used is as follows:

1 /// <summary> 2 /// Control Center 3 /// </summary> 4 public class CenterController 5 {6 /// <summary> 7 // at startup behavior 8 // </summary> 9 public void StartBef () 10 {11 Component1 com1 = new Component1 (); 12 com1.Component1Inspection (); 13 Component2 com2 = new Component2 (); 14 com2.Component2Inspection (); 15 Component3 com3 = new Component3 (); 16 com3.Component3Inspection (); 17} 18}

In this case, it is not very troublesome, and the coupling degree between the control center and the components is also relatively large. If the number of components is self-checked, modifications within the control center will also be involved, such behavior violates the design principles.

 

Facade: provides a consistent interface for a group of interfaces in the subsystem to access a group of interfaces in the subsystem.

 

According to the central idea of the design mode, the self-check operations of components are encapsulated in a separate layer to decouple the control center and components. Let's take a look at the modified Code:

1 public class Facade 2 {3 // self-check 4 public void Inspection () 5 {6 Component1 com1 = new Component1 (); 7 com1.Component1Inspection (); 8 Component2 com2 = new Component2 (); 9 com2.Component2Inspection (); 10 Component3 com3 = new Component3 (); 11 com3.Component3Inspection (); 12} 13}

After defining the appearance class, let's take a look at the call changes of the Control Center:

1 /// <summary> 2 /// Control Center 3 /// </summary> 4 public class CenterController 5 {6 /// <summary> 7 // at startup behavior 8 // </summary> 9 public void StartBef () 10 {11 Facade facade = new Facade (); 12 facade. inspection (); 13} 14}

The Facade layer is added between the two layers to solve the coupling problem. It seems that many decoupling methods are like this.

 

END the next article describes the command mode.

 

 

 

Author: Jin Yuan

Source: http://www.cnblogs.com/jin-yuan/

The copyright of this article is shared by the author and the blog Park. You are welcome to reprint this article. However, you must keep this statement without the author's consent and go to the Article Page.

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.