ASP.NET---- Microsoft .NET Pet Shop 3.x(二)

正在学习PetShop3.x,现将一些自己的一些总结写出来.
PetShop3.x分层分得很清楚,分别为UI,Business Layer,Data  Access Layer,典型的N层体系结构.表现的
非常棒.
但是仔细一看源代码,发现并不是那么简单分清楚,原因就是在表现Data Access layer时,做了一些易于扩展的
架构,那就时工厂模式.所以为了把它搞清出,我专门选了一个功能来研究,其他的功能基本上都是一样,大同小异了.我挑选的是Product这个.
先来一张图:

可以看到,PetShop.Web的Catagory调用BLL层里的Product,
代码如下:可以在catagory.aspx.cs中找到
 // Check to see if the contents are in the Data Cache
   if(Cache[categoryKey] != null){
    // If the data is already cached, then used the cached copy
    products.DataSource = (IList)Cache[categoryKey];
   }else{
    // If the data is not cached, then create a new products object and request the data
    Product product = new Product();
    IList productsByCategory = product.GetProductsByCategory(categoryKey);

    // Store the results of the call in the Cache and set the time out to 12 hours
    Cache.Add(categoryKey, productsByCategory, null, DateTime.Now.AddHours(12), Cache.NoSlidingExpiration , CacheItemPriority.High, null);
    products.DataSource = productsByCategory;
   }

而PetShop.BLL.Product的GetProductsByCategory是如何处理的呢?
看看如下代码
 public IList GetProductsByCategory(string category) {

   // Return null if the string is empty
   if (category.Trim() == string.Empty)
    return null;

   // Get an instance of the Product DAL using the DALFactory
   IProduct dal = PetShop.DALFactory.Product.Create();

   // Run a search against the data store
   return dal.GetProductsByCategory(category);

  }

上面就是其实现代码了.我们会发现用到了了PetShop.DALFactory,这个就是工厂模式了.Create了一个IProduct的实例.其实
这个时候它创建的是来自PetShop.SQLServerDAL的Product类,所以调用的是 PetShop.SQLServerDAL.Product.GetProductByCatagory方法,而不是 PetShop.OracleDAL.Product.GetProductByCatagory.关于这个以后再来讨论.
说到这里,我想我对他的如何调用都熟悉了.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值