亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#設(shè)計模式之Facade外觀模式解決天河城購物問題示例

 更新時間:2017年09月15日 09:40:21   作者:GhostRider  
這篇文章主要介紹了C#設(shè)計模式之Facade外觀模式解決天河城購物問題,簡單描述了外觀模式的定義并結(jié)合具體實例分析了外觀模式解決購物問題的相關(guān)步驟與操作技巧,需要的朋友可以參考下

本文實例講述了C#設(shè)計模式之Facade外觀模式解決天河城購物問題。分享給大家供大家參考,具體如下:

一、理論定義

外觀模式   把  分散的子系統(tǒng),集合成一個系統(tǒng),提供一站式服務(wù)。

二、應(yīng)用舉例

需求描述: 聶小倩 和 寧采臣是一對小富則安 的聊齋夫妻。住在比較偏遠的小鄉(xiāng)村。
今天,兩人初次來到大城市廣州,聽說天河城提供一站式服務(wù),不像小城市那樣,買個東西  得  東奔西跑。
在一個地方,就可以買到 自己想要的衣服,電腦,鞋子,Iphone,還可以看大片,
吃冰淇淋,吃真功夫,買化妝品,珠寶首飾。天河城,果然是一寶地啊。
Ok,邊走邊看。

三、具體編碼

1.阿迪達斯

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// 阿迪達斯
  /// </summary>
  public class Adidas
  {
    public void Serivce(string something) {
      Console.WriteLine("在阿迪達斯購買了: "+something);
    }
  }
}

2.飛揚影城

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// 飛揚影城
  /// </summary>
  public class FeiYangMovie
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在飛揚影城看了一部電影: " + something);
    }
  }
}

3.國美電器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// 國美電器
  /// </summary>
  public class GoMe
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在國美電器 買了: " + something);
    }
  }
}

4.哈根達斯

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// 哈根達斯
  /// </summary>
  public class HaagenDaz
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在哈根達斯 買了: " + something);
    }
  }
}

5.真功夫

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// 真功夫
  /// </summary>
  public class KungFu
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在真功夫 吃了: " + something);
    }
  }
}

6.六福珠寶

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// 六福珠寶
  /// </summary>
  public class LukFook
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在六福珠寶 買了: " + something);
    }
  }
}

7.耐克

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// 耐克
  /// </summary>
  public class NIKE
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在耐克店 買了: " + something);
    }
  }
}

8.ONLY

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// ONLY時裝
  /// </summary>
  public class ONLY
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在ONLY時裝 買了: " + something);
    }
  }
}

9.蘇寧電器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// 蘇寧電器
  /// </summary>
  public class Suning
  {
    public void Serivce(string something)
    {
      Console.WriteLine("在蘇寧電器 買了: " + something);
    }
  }
}

10.Veromoda國際時裝品牌

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// Veromoda國際時裝品牌
  /// </summary>
  public class Veromoda
  {
    public void Serivce(string something)
    {
      Console.WriteLine(something);
    }
  }
}

11.消費者

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// 消費店子
  /// </summary>
  public enum ShopOption
  {
    Adidas = 1, DKNY = 2, GoMe = 3,
    NIKE = 4, Suning = 5, Veromoda = 6,
    FeiYangMovie = 7, HaagenDaz = 8, LukFook = 9, KungFu = 10
  }
  /// <summary>
  /// 消費單
  /// </summary>
  public class Bill {
    /// <summary>
    /// 要去的消費店
    /// </summary>
    public ShopOption Item { get; set; }
    /// <summary>
    /// 去這個店要買啥
    /// </summary>
    public string Something { get; set; }
  }
  public class Consumer
  {
    /// <summary>
    /// 消費單
    /// </summary>
    public IList<Bill> Items { get; set; }
    /// <summary>
    /// 姓名
    /// </summary>
    public string Name { get; set; }
  }
}

12.天河城---一站式服務(wù)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace Com.Design.Gof.Facade
{
  /// <summary>
  /// 天河城
  /// </summary>
  public class TeeMall
  {
    private static readonly Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + @"\Com.Design.Gof.dll");
    /// <summary>
    /// 一站式服務(wù)
    /// </summary>
    /// <param name="consumer"></param>
    public void OfferService(Consumer consumer) {
      Console.WriteLine("我是: " + consumer.Name+",不差錢,今天來天河城玩: ");
      Console.WriteLine("----------------------------------------------");
      foreach (Bill item in consumer.Items)
      {
        object obj= assembly.CreateInstance("Com.Design.Gof.Facade." + item.Item);
        MethodInfo info = obj.GetType().GetMethod("Serivce");
        info.Invoke(obj, new object[] { item.Something });
      }
      Console.WriteLine();
    }
  }
}

13.主函數(shù)調(diào)用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.Design.Gof.Facade;
namespace Com.Design.Gof.Test
{
  class Program
  {
    static void Main(string[] args)
    {
      //天河城購物中心
      TeeMall TeeMall = new TeeMall();
      //消費者 1
      Consumer consumer = new Consumer
      {
        Name="聶小倩",
        //消費單
        Items = new List<Bill> {
         new Bill{ Item=ShopOption.Adidas, Something="運動服"},
         new Bill{ Item=ShopOption.GoMe, Something="蘋果IPhone智能手機"},
         new Bill{ Item=ShopOption.FeiYangMovie, Something="<冰河世紀 4>"},
         new Bill{ Item=ShopOption.KungFu, Something="香菇燉雞"},
          new Bill{ Item=ShopOption.LukFook, Something="金項鏈"},
        }
      };
      TeeMall.OfferService(consumer);
      //消費者 2
      consumer = new Consumer
      {
        Name = "寧采臣",
        //消費單
        Items = new List<Bill> {
         new Bill{ Item=ShopOption.FeiYangMovie, Something="《太空一號》"},
         new Bill{ Item=ShopOption.Veromoda, Something="然后去了Veromoda時裝,買了一套服裝"},
         new Bill{ Item=ShopOption.HaagenDaz, Something="買了一雪糕"},
         new Bill{ Item=ShopOption.Suning, Something="在蘇寧看買平板電腦"},
        }
      };
      TeeMall.OfferService(consumer);
      Console.ReadKey();
    }
  }
}

14.運行結(jié)果

15.總結(jié)

天河城 TeeMall 理論上應(yīng)該包括 所有 商場的引用,

這里用反射 避免了這一動作。

附:完整實例代碼點擊此處本站下載。

更多關(guān)于C#相關(guān)內(nèi)容還可查看本站專題:《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#窗體操作技巧匯總》、《C#常見控件用法教程》、《WinForm控件用法總結(jié)》、《C#數(shù)組操作技巧總結(jié)》及《C#面向?qū)ο蟪绦蛟O(shè)計入門教程

希望本文所述對大家C#程序設(shè)計有所幫助。

相關(guān)文章

  • C#中如何使用redis

    C#中如何使用redis

    這篇文章主要介紹了C#中如何使用redis,文中示例代碼非常詳細,幫助大家更好的理解和學習,感興趣的朋友可以了解下
    2020-07-07
  • C#中委托用法實例分析

    C#中委托用法實例分析

    這篇文章主要介紹了C#中委托用法,較為詳細的分析了C#中委托的概念與相關(guān)的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-05-05
  • C#多種操作excel的方法比較

    C#多種操作excel的方法比較

    本文詳細講解了C#多種操作excel的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-12-12
  • C#繪圖基本方法實例總結(jié)

    C#繪圖基本方法實例總結(jié)

    C#要實現(xiàn)簡單的畫圖功能可以利用Graphics這個類,下面這篇文章主要給大家介紹了關(guān)于C#繪圖基本方法的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-12-12
  • C#實現(xiàn)自定義定時組件的方法

    C#實現(xiàn)自定義定時組件的方法

    這篇文章主要介紹了C#實現(xiàn)自定義定時組件的方法,很實用的功能,需要的朋友可以參考下
    2014-08-08
  • 使用C#語言實現(xiàn)的查詢條件界面展開和收起功能

    使用C#語言實現(xiàn)的查詢條件界面展開和收起功能

    這篇文章主要介紹了使用C#語言實現(xiàn)的查詢條件界面展開和收起功能的完美解決方案,需要的朋友可以參考下
    2016-11-11
  • CDMA 貓用AT命令發(fā)中文短信(C#)

    CDMA 貓用AT命令發(fā)中文短信(C#)

    CDMA貓連PDU都不支持,只能發(fā)文本短信。而且發(fā)中文短信居然是UNICODE,無法在超級終端里輸入。只能寫程序。網(wǎng)上這個問題談?wù)摰乇容^多,做起來比較累,還偶爾會出亂碼。還是將C#的成功代碼帖一下吧。
    2009-08-08
  • c#基于Win32Api實現(xiàn)返回Windows桌面功能

    c#基于Win32Api實現(xiàn)返回Windows桌面功能

    本文分享下回到桌面功能的實現(xiàn)方法,效果與快捷鍵(Win+D)相同。有此需求的朋友可以參考下
    2021-05-05
  • C#設(shè)計模式之Visitor訪問者模式解決長隆歡樂世界問題實例

    C#設(shè)計模式之Visitor訪問者模式解決長隆歡樂世界問題實例

    這篇文章主要介紹了C#設(shè)計模式之Visitor訪問者模式解決長隆歡樂世界問題,簡單描述了訪問者模式的定義并結(jié)合具體實例形式分析了C#使用訪問者模式解決長隆歡樂世界問題的具體實現(xiàn)技巧,需要的朋友可以參考下
    2017-09-09
  • C#創(chuàng)建數(shù)據(jù)庫及附加數(shù)據(jù)庫的操作方法

    C#創(chuàng)建數(shù)據(jù)庫及附加數(shù)據(jù)庫的操作方法

    這篇文章主要介紹了C#創(chuàng)建數(shù)據(jù)庫及附加數(shù)據(jù)庫的操作方法,涉及C#針對數(shù)據(jù)庫常見的創(chuàng)建、添加、連接等操作技巧,需要的朋友可以參考下
    2016-06-06

最新評論