小弟刚开始研究PetShop
发现里面的生成类的对象时
全是调用的DataAccess里面的
Assembly.Load(path).CreateInstance(className);这个方法
请问一个这样返回一个对象,和直接New这个对象有什么区别?
另外,我在写程序时,都是声明的IDAL对象,接收New的DAL,
然后用这个IDAL的对象调用方法,这样做对吗,这样做有什么好处?
刚开始研究这类的东西,高手们见谅了。。。
------解决方案--------------------------------------------------------
第一条我明白,
就是不知道第二条怎么实现,有没有例子可以看啊?
简单点的例子
-----------------
参看petshop:
- C# code
public sealed class DataAccess { // Look up the DAL implementation we should be using private static readonly string path = ConfigurationManager.AppSettings["WebDAL"]; private static readonly string orderPath = ConfigurationManager.AppSettings["OrdersDAL"]; private DataAccess() { } public static PetShop.IDAL.ICategory CreateCategory() { string className = path + ".Category"; return (PetShop.IDAL.ICategory)Assembly.Load(path).CreateInstance(className); }}
------解决方案--------------------------------------------------------