我也设计模式——7.反射工厂

反射工厂是.NET独有的,因为它基于反射机制,可以用来简化工厂类。

        public static object CreateByReflection(string strType)
        
{
            Type t 
= Type.GetType(strType);
            ConstructorInfo ci 
= t.GetConstructor(System.Type.EmptyTypes);
            
return ci.Invoke(null);
        }

几个要点:
    1.strType可以由配置文件动态读取。
    2.通过反射构造函数,构造一个对象并返回。

VS2005中的智能引擎就是用反射工厂做的。

posted @ 2007-10-02 00:22  包建强  Views(668)  Comments(0Edit  收藏  举报