日期:2014-05-19  浏览次数:20400 次

[分享]简单工厂+反射的一个学习例子
嘿嘿,新手参考学习~~~大鸟表笑话俺,哈哈~~

using   System;

namespace   DesignPatterns
{


        public   interface   Fruit   //具体产品的抽象
        {
                string   Color   {   get;set;}
        }


        public   class   Orange   :   Fruit
        {
                private   string   color;

                public   Orange(){   }

                public   string   Color
                {
                        get   {   return   color;   }
                        set   {   color   =   value;   }
                }
        }


       
        public   class   Apple   :   Fruit
        {
                private   string   color;

                public   Apple()   {   }

                public   string   Color
                {
                        get   {   return   color;   }
                        set   {   color   =   value;   }
                }
        }


        public   class   FruitFactory   //工厂类
        {
                /*==========================================================================
                  *   注意:这里的name格式为:namespace.class!否则type的返回值一定是null
                  *==========================================================================*/
                public   static   Fruit   CreateFruit(string   name)
                {
                        Fruit   fruit   =   null;
                        /*=============================================================================
                          *   System.Type类:           它对于反射起着核心的作用。我们可以使用   Type   对象的
                          *                   &n