Solve the problem of Teem shopping in C# Facade appearance mode

黄舟
Release: 2017-09-15 11:22:33
Original
1388 people have browsed it

This article mainly introduces the Facade appearance mode of C# design pattern to solve shopping problems in Teemall. It briefly describes the definition of appearance mode and analyzes the relevant steps and operation skills of appearance mode to solve shopping problems with specific examples. Friends in need You can refer to the following

The example of this article describes how the Facade appearance mode of the C# design pattern solves the shopping problem of Tianhe City. Share it with everyone for your reference, the details are as follows:

1. Theoretical definition

Appearance mode integrates scattered subsystems into one system , providing one-stop service.

2. Application examples

Demand description: Nie Xiaoqian and Ning Caichen are a couple who are wealthy and peaceful. Live in a relatively remote small village.
Today, the two came to the big city Guangzhou for the first time. They heard that Tianhe City provides one-stop service, unlike small cities where you have to run around to buy something.
In one place, you can buy the clothes, computers, shoes, and iPhones you want, and you can also watch blockbuster movies,
eat ice cream, learn real kung fu, and buy cosmetics and jewelry. Tianhe City is indeed a treasure.
Ok, watch while walking.

3. Specific coding

1.Adidas


##

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Com.Design.Gof.Facade { ///  /// 阿迪达斯 ///  public class Adidas { public void Serivce(string something) { Console.WriteLine("在阿迪达斯购买了: "+something); } } }
Copy after login

2.Feiyang Cinema


using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Com.Design.Gof.Facade { ///  /// 飞扬影城 ///  public class FeiYangMovie { public void Serivce(string something) { Console.WriteLine("在飞扬影城看了一部电影: " + something); } } }
Copy after login

3. Gome Electric


using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Com.Design.Gof.Facade { ///  /// 国美电器 ///  public class GoMe { public void Serivce(string something) { Console.WriteLine("在国美电器 买了: " + something); } } }
Copy after login

4.Haagen-Dazs


using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Com.Design.Gof.Facade { ///  /// 哈根达斯 ///  public class HaagenDaz { public void Serivce(string something) { Console.WriteLine("在哈根达斯 买了: " + something); } } }
Copy after login

5. Real Kung Fu


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

6. Luk Fook Jewelry


using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Com.Design.Gof.Facade { ///  /// 六福珠宝 ///  public class LukFook { public void Serivce(string something) { Console.WriteLine("在六福珠宝 买了: " + something); } } }
Copy after login

7. Nike


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

8.ONLY


using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Com.Design.Gof.Facade { ///  /// ONLY时装 ///  public class ONLY { public void Serivce(string something) { Console.WriteLine("在ONLY时装 买了: " + something); } } }
Copy after login

9.Suning Appliance


using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Com.Design.Gof.Facade { ///  /// 苏宁电器 ///  public class Suning { public void Serivce(string something) { Console.WriteLine("在苏宁电器 买了: " + something); } } }
Copy after login

10.Veromoda international fashion brand


using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Com.Design.Gof.Facade { ///  /// Veromoda国际时装品牌 ///  public class Veromoda { public void Serivce(string something) { Console.WriteLine(something); } } }
Copy after login

11.Consumer


using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Com.Design.Gof.Facade { ///  /// 消费店子 ///  public enum ShopOption { Adidas = 1, DKNY = 2, GoMe = 3, NIKE = 4, Suning = 5, Veromoda = 6, FeiYangMovie = 7, HaagenDaz = 8, LukFook = 9, KungFu = 10 } ///  /// 消费单 ///  public class Bill { ///  /// 要去的消费店 ///  public ShopOption Item { get; set; } ///  /// 去这个店要买啥 ///  public string Something { get; set; } } public class Consumer { ///  /// 消费单 ///  public IList Items { get; set; } ///  /// 姓名 ///  public string Name { get; set; } } }
Copy after login

12. Tianhe City---one-stop service


using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; namespace Com.Design.Gof.Facade { ///  /// 天河城 ///  public class TeeMall { private static readonly Assembly assembly = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + @"\Com.Design.Gof.dll"); ///  /// 一站式服务 ///  ///  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(); } } }
Copy after login

13. Main function call


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 { 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 { 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(); } } }
Copy after login

14. Running results

15. Summary

Teemall TeeMall should theoretically include references to all shopping malls,

reflection is used here to avoid this One action.

The above is the detailed content of Solve the problem of Teem shopping in C# Facade appearance mode. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!