首页 > 其他 > 详细

传统抽象工厂(通过反射来创建实例)-》目的为了解耦

时间:2017-06-14 17:37:21      阅读:334      评论:0      收藏:0      [点我收藏+]
//第一步创建一个AbstractFactory类,在这个类里面定义两个静态属性:AssemblyPath ,NameSpace 
//第二步在工厂类里面写一个静态方法:public static IUserInfoDal CreateUserInfoDal(){}
//第三步再写一个方法:private static object CreateInstance(string fullName)通过Assembly反射来创建实例
//第四步在web.config文件下配置这两个静态属性:AssemblyPath ,NameSpace

public class AbstractFactory { private static readonly string AssemblyPath = ConfigurationManager.AppSettings["AssemblyPath"]; private static readonly string NameSpace = ConfigurationManager.AppSettings["NameSpace"]; public static IUserInfoDal CreateUserInfoDal() { string fullName = NameSpace + ".UserInfoDal"; return CreateInstance(fullName) as IUserInfoDal; } private static object CreateInstance(string fullName) { Assembly assembly = Assembly.Load(AssemblyPath); return assembly.CreateInstance(fullName); } }

  技术分享

 

传统抽象工厂(通过反射来创建实例)-》目的为了解耦

原文:http://www.cnblogs.com/BOSET/p/7009935.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!