This article mainly introduces the facade appearance mode of C # design mode to solve the shopping problem of Tianhe City, simply describes the definition of the appearance pattern and analyzes the related steps and operation skills of the appearance mode to solve the shopping problem with the concrete example, and the friends who need can refer to the following
This paper describes the facade appearance mode of C # design mode to solve the shopping problem of Tianhe City. Share to everyone for your reference, as follows:
I. Definition of theory
The exterior mode integrates a decentralized subsystem into one system, providing one-stop service.
Ii. Examples of application
Requirements Description: Xiaoqian and princes are a couple of small rich Ann's strange Tales. Living in a relatively remote small village.
Today, the two first came to the big city of Guangzhou, heard that Tianhe City provides a one-stop service, not like a small city, buy something to go around.
In one place, you can buy the clothes you want, your computer, your shoes, your Iphone, you can watch blockbusters,
Eat ice cream, eat real kung fu, buy cosmetics, jewelry. Tianhe City, is indeed a treasure.
Ok, watch while you walk.
Third, the specific code
1. Adidas
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ //<summary>//Adidas///</summary> public class Adidas {public void Serivce ( String something) { Console.WriteLine ("Purchased in Adidas:" +something);} }
2. Flying Shadow City
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ //<summary>//Flying Studios/// </summary> public class Feiyangmovie { public void Serivce (string something) { Console.WriteLine ("Saw a movie in Flying studios:" + Something);}}
3. Gome Electric
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ //<summary>///Gome///</summary> public class GoMe {public void Serivce ( String something) { Console.WriteLine ("Bought in Gome:" + Something);}}
4. Haagen Dazs
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ //<summary>/Haagen-Dazs// </summary> public class Haagendaz { public void Serivce (string something) { Console.WriteLine ("Bought at Haagen-Dazs:" + Something);} }}
5. Real Kung Fu
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ //<summary>///Real Kung Fu//</summary> public class KungFu {public void Serivce ( String something) { Console.WriteLine ("Ate in real Kung fu:" + something); } }
6. Six Lucky Jewels
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ //<summary>// six Fook jewellery///</summary> public class Lukfook {public void Serivce (string something) { Console.WriteLine ("In Six Fu Jewels bought:" + something);} } }
7. Nike
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ //<summary>///Nike//</summary> public class Nike {public void Serivce ( String something) { Console.WriteLine ("Bought at Nike store:" + something);} }
8.ONLY
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ //<summary>//Only fashion/// </summary> public class-{public void Serivce (string something) { Console.WriteLine ("Bought in only fashion:" + something);} } }
9. Suning Appliance
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ //<summary>//Suning appliances///</summary> public class Suning {public void Serivce ( String something) { Console.WriteLine ("Bought in Suning appliance:" + something);} }
10.Veromoda International fashion Brand
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ ///<summary>// Veromoda International fashion brands/// </summary> public class Veromoda { public void Serivce (string something) { Console.WriteLine (something);}} }
11. Consumers
Using system;using system.collections.generic;using system.linq;using system.text;namespace Com.Design.Gof.Facade{ //<summary>/// Consumer Shop sub///</summary> public enum shopoption { Adidas = 1, DKNY = 2 , GoMe = 3, NIKE = 4, Suning = 5, Veromoda = 6, Feiyangmovie = 7, Haagendaz = 8, Lukfook = 9, KungFu = ten }
///<summary> ///Consumption list ///</summary> public class Bill { ///<summary>/ To go to the consumer shop/// </summary> public shopoption Item {get; set;} <summary>/////to the store./// </summary> public string Something {get; set;} } public class Consumer {//<summary>//// </summary> public ilist< Bill> Items {get; set;} <summary>///Name:/// </summary> Public string name {get; set; }}
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{//<summary>//Tianhe City/// </summary> public class Teemall { private static readonly Assembly Assembly = assembly.loadfile (AppDomain.CurrentDomain.BaseDirectory + @ "\ Com.Design.Gof.dll "); <summary>/// One-stop service///</summary>// <param name= "consumer" ></param> Public void Offerservice (Consumer Consumer) { Console.WriteLine ("I am:" + Consumer. Name+ ", not bad money, today to the Tianhe City Play:"); 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. 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) {//Tianhe City Shopping center Teemall TeeMa ll = new Teemall (); Consumer 1 Consumer Consumer = new Consumer {name= "Xiaoqian"//consumption order Items = new List<bill> { New bill{Item=shopoption.adidas, something= "sportswear"}, new bill{item=shopoption.gome, something= "Apple iphone Smart Mobile "}, new bill{Item=shopoption.feiyangmovie, something=" < Ice Age 4> "}, new bill{ITEM=SHOPOPTION.KUNGF U, something= "mushroom Stew Chicken"}, new bill{Item=shopoption.lukfook, something= "Gold Necklace"},}}; Teemall.offerservice (consumer); Consumer 2 consumer = new Consumer {Name = "princes",//consumption order Items = new List<bill> { New bill{Item=shopoption.feiyangmovie, something= "Space One"}, new bill{Item=shopoption.veromoda, SometHing= "then went to Veromoda fashion, bought a Suit"}, new bill{Item=shopoption.haagendaz, something= "bought an ice Cream"}, new bill{Item=sho Poption.suning, something= "in suning See Buy tablet"},}; Teemall.offerservice (consumer); Console.readkey (); } }}
14. Running Results
15. Summary
Tianhe City Teemall should theoretically include references to all the malls,
This action is avoided by reflection here.