4. Abstract Factory mode (Factory)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.