大話設計模式讀書筆記10—-面板模式(Facade)

來源:互聯網
上載者:User

面板模式(Facade):為子系統中的一組介面提供一個一致的介面,此模式定義了一個高層介面,這個介面使得這一子系統更容易使用。

1、在設計初級階段,應該要有意識的將不同的兩個層分離。

2、層與層之間建立外觀Facade,為複雜的子系統提供一個簡單的介面,使得耦合大大降低。

3、在開發階段,子系統往往因為不斷的重構演化而變得越來越複雜。

4、增加 Facade可以提供一個簡單的介面,減少他們之間的依賴。

Facade代碼 1 using System;
 2 using System.Collections.Generic;
 3 using System.Text;
 4 
 5 namespace Facade
 6 {
 7     class Program
 8     {
 9         static void Main(string[] args)
10         {
11             Facade facade = new Facade();
12             facade.MethodA();          //由於Facade的作用,用戶端可以根本不知道SubSystemOne,SubSystemTwo等。
13             Console.ReadLine();
14         }
15     }
16     class Facade
17     {
18         SubSystemOne one;
19         SubSystemTwo two;
20         SubSystemThree three;
21         public Facade()
22         {
23             one = new SubSystemOne();
24             two = new SubSystemTwo();
25             three = new SubSystemThree();
26         }
27         public void MethodA()
28         {
29             Console.WriteLine("方法組A()----");
30             one.MethodOne();
31             two.MethodTwo();
32             three.MethodThree();
33         }
34     }
35     class SubSystemOne
36     {
37         public void MethodOne()
38         {
39             Console.WriteLine("子系統方法一");
40         }
41     }
42     class SubSystemTwo
43     {
44         public void MethodTwo()
45         {
46             Console.WriteLine("子系統方法二");
47         }
48     }
49     class SubSystemThree
50     {
51         public void MethodThree()
52         {
53             Console.WriteLine("子系統方法三");
54         }
55     }
56 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.