usingSystem;usingSystem.Reflection;namespaceconsoleapplication1{classProgram {Static voidMain (string[] args) { //In this way, I plant in Hunan to change the factory in Guangzhou abstract factory class instance object on it, on the product duck shelf, duck neck did not affect//abstractfactory nanchangfactory = new Guanzhoufactory ();Abstractfactory nanchangfactory =Newhunanfactory (); Yabo _yabo=Nanchangfactory.createyabo (); Yajia _yajia=Nanchangfactory.createyajia (); _yabo. Make (); _yajia. Make (); Console.ReadLine (); } } /// <summary> ///Abstract Factory class, providing an interface to create two different locations for duck racks and duck necks/// </summary> Public Abstract classAbstractfactory {//Abstract Factory provides an interface for creating a series of products, here as an example, only the creation interface of the duck neck and the duck rack is given. Public AbstractYabo Createyabo (); Public AbstractYajia Createyajia (); } /// <summary> ///Guangzhou Taste Factory is responsible for the production of Guangzhou duck neck and duck rack/// </summary> Public classGuanzhoufactory:abstractfactory { Public OverrideYabo Createyabo () {return NewGuanzhouyabo (); } Public OverrideYajia Createyajia () {return NewGuanzhouyajia (); } } /// <summary> ///Hunan Taste Factory is responsible for the production of Hunan Duck neck and duck rack/// </summary> Public classHunanfactory:abstractfactory { Public OverrideYabo Createyabo () {return NewHunanyabo (); } Public OverrideYajia Createyajia () {return NewHunanyajia (); } } /// <summary> ///Duck Rack abstract class, for each place to inherit the Duck rack class/// </summary> Public Abstract classYabo { Public Abstract voidMake (); } /// <summary> ///Duck Rack abstract class, for each place to inherit the Duck rack class/// </summary> Public Abstract classYajia { Public Abstract voidMake (); } /// <summary> ///Guangzhou Duck Neck category, generally spicy/// </summary> Public classGuanzhouyabo:yabo { Public Override voidMake () {Console.WriteLine ("the duck neck in Guangzhou"); } } /// <summary> ///the duck neck of Hunan, more spicy/// </summary> Public classHunanyabo:yabo { Public Override voidMake () {Console.WriteLine ("the duck neck of Hunan"); } } /// <summary> ///Duck Racks in Guangzhou, generally spicy/// </summary> Public classGuanzhouyajia:yajia { Public Override voidMake () {Console.WriteLine ("Duck Racks in Guangzhou"); } } /// <summary> ///Duck Racks in Hunan, more spicy/// </summary> Public classHunanyajia:yajia { Public Override voidMake () {Console.WriteLine ("Duck racks in Hunan"); } }}
4. Abstract Factory mode (Factory)