Provider模式

总结起来,Provider模式是,一个接口以及所有实现这个接口的类,一个实用类,这个实用类相当于是接口及其实现类的代理,外部系统通过这个类实现相关的所有功能。实现接口与具体实现的分离,通过配制文件灵活配制需要的具体实现.

//IPetShopProfileProvider主接口

private static readonly IPetShopProfileProvider dal =DataAccess.CreatePetShopProfileProvider();

//获取配置文件中参数加载并创建实例

private static readonly string profilePath = ConfigurationManager.AppSettings["ProfileDAL"];
  public static PetShop.IProfileDAL.IPetShopProfileProvider CreatePetShopProfileProvider() {
   string className = profilePath + ".PetShopProfileProvider";
   return (PetShop.IProfileDAL.IPetShopProfileProvider)Assembly.Load(profilePath).CreateInstance(className);
  }

posted on 2011-04-13 14:55  netyaya  阅读(539)  评论(0)    收藏  举报

导航