Factory mode of C # design mode

Source: Internet
Author: User
wrap up the things that create objects

Using system;using system.collections.generic;using system.linq;using system.text;namespace DesignPytternDemo{//&    Lt;summary>///Simple factory///</summary> public interface Ifood {int. price {get;}        } public class Orange:ifood {public orange () {Console.WriteLine ("Orange created");            } public int Price {get {return 1; }}} public class Rice:ifood {public rice () {Console.WriteLine ("Rice created        ");            } public int Price {get {return 3;            }}} public static class Foodfactory {public static Ifood Createfood (string foodtype) {            Ifood f = null;                    Switch (foodtype) {case "o": F = new Orange ();                Break            Case "R":        f = new Rice ();                Break            Default:break;        } return F; }}///<summary>//Abstract Factory///</summary> public interface Iactiongame {} public Clas        s Kof:iactiongame {public Kof () {Console.WriteLine ("Kof created");         }} public class War3:iactiongame {public War3 () {Console.WriteLine ("War3 created"); }} public class Cs:iactiongame {public cs () {Console.WriteLine ("CS created")        );            }} public interface IRPG {} public class Menghuan:irpg {public Menghuan () {        Console.WriteLine ("Menghuan created");        }} public class Legend:irpg {public Legend () {Console.WriteLine ("Legend created");     }} public class Diablo:irpg {public Diablo () {       Console.WriteLine ("Diablo created");        }} public abstract class Gamefactory {public abstract iactiongame createactiongame ();    Public abstract IRPG createrpggame ();            } public class Mygamefactory:gamefactory {public override Iactiongame Createactiongame () {        return new Kof ();        } public override Irpg Createrpggame () {return new Legend (); }    }}

The above is the C # design mode of the factory model content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.