這篇文章給大家分享的是有關C#設計模式之Facade外觀模式如何解決天河城購物的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
謝通門ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!具體如下:
一、理論定義
外觀模式 把 分散的子系統(tǒng),集合成一個系統(tǒng),提供一站式服務。
二、應用舉例
需求描述: 聶小倩 和 寧采臣是一對小富則安 的聊齋夫妻。住在比較偏遠的小鄉(xiāng)村。
今天,兩人初次來到大城市廣州,聽說天河城提供一站式服務,不像小城市那樣,買個東西 得 東奔西跑。
在一個地方,就可以買到 自己想要的衣服,電腦,鞋子,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.天河城---一站式服務
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>
/// 一站式服務
/// </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é)果

感謝各位的閱讀!關于“C#設計模式之Facade外觀模式如何解決天河城購物”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
名稱欄目:C#設計模式之Facade外觀模式如何解決天河城購物-創(chuàng)新互聯(lián)
本文地址:http://chinadenli.net/article20/ccjeco.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、靜態(tài)網(wǎng)站、品牌網(wǎng)站設計、網(wǎng)站收錄、定制網(wǎng)站、關鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容