我对petshop4的简单理解!
来源:互联网 发布:2016征兵心理测试软件 编辑:程序博客网 时间:2024/05/17 23:03
petshop4充分体现了面向接口编程的思想,就是给你一个接口你别管我是怎么实现的,你只管用别说其他的。
namespace PetShop.BLL {
/// <summary> /// A business component to manage products /// </summary> public class Product {
// Get an instance of the Product DAL using the DALFactory // Making this static will cache the DAL instance after the initial load private static readonly IProduct dal = PetShop.DALFactory.DataAccess.CreateProduct();
在bll层,这里使用创建Produce的接口,你只管调用他的方法。
namespace PetShop.IDAL{ /// <summary> /// Interface for the Product DAL /// </summary> public interface IProduct{ /// <summary> /// Method to search products by category name /// </summary> /// <param name="category">Name of the category to search by</param> /// <returns>Interface to Model Collection Generic of search results</returns> IList<ProductInfo> GetProductsByCategory(string category);
/// <summary> /// Method to search products by a set of keyword /// </summary> /// <param name="keywords">An array of keywords to search by</param> /// <returns>Interface to Model Collection Generic of search results</returns> IList<ProductInfo> GetProductsBySearch(string[] keywords);
/// <summary> /// Query for a product /// </summary> /// <param name="productId">Product Id</param> /// <returns>Interface to Model ProductInfo for requested product</returns> ProductInfo GetProduct(string productId); }
这里是定义了Product接口和他的虚方法。
namespace PetShop.SQLServerDAL {
public class Product : IProduct {
//Static constants private const string SQL_SELECT_PRODUCTS_BY_CATEGORY = "SELECT Product.ProductId, Product.Name, Product.Descn, Product.Image, Product.CategoryId FROM Product WHERE Product.CategoryId = @Category"; private const string SQL_SELECT_PRODUCTS_BY_SEARCH1 = "SELECT ProductId, Name, Descn, Product.Image, Product.CategoryId FROM Product WHERE (("; private const string SQL_SELECT_PRODUCTS_BY_SEARCH2 = "LOWER(Name) LIKE '%' + {0} + '%' OR LOWER(CategoryId) LIKE '%' + {0} + '%'"; private const string SQL_SELECT_PRODUCTS_BY_SEARCH3 = ") OR ("; private const string SQL_SELECT_PRODUCTS_BY_SEARCH4 = "))"; private const string SQL_SELECT_PRODUCT = "SELECT Product.ProductId, Product.Name, Product.Descn, Product.Image, Product.CategoryId FROM Product WHERE Product.ProductId = @ProductId"; private const string PARM_CATEGORY = "@Category"; private const string PARM_KEYWORD = "@Keyword"; private const string PARM_PRODUCTID = "@ProductId";
/// <summary> /// Query for products by category /// </summary> /// <param name="category">category name</param> /// <returns>A Generic List of ProductInfo</returns> public IList<ProductInfo> GetProductsByCategory(string category) {
IList<ProductInfo> productsByCategory = new List<ProductInfo>();
这里是实现Product接口的类,
namespace PetShop.DALFactory {
/// <summary> /// This class is implemented following the Abstract Factory pattern to create the DAL implementation /// specified from the configuration file /// </summary> 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); }
这里是利用工厂模式来映射你需要你想创建哪一个。
后面还有一些消息队列MSMQMessage利用cache缓存以后达到异步处理购物车里订单的功能!
刚开始看应先从先从Product入口,关于Product的一些操作串联起来看一遍!
- 我对petshop4的简单理解!
- 我对BroadcastReceiver的简单理解
- 我对MVP的简单理解
- 我对线程的简单理解
- 浅析对PetShop4.0的工厂模式的理解
- 我对属性的简单理解(C#)
- 简单谈谈我对JVM内存管理的理解(1)
- 简单谈谈我对JVM内存管理的理解(2)
- 简单总结我对单例模式的理解
- 说说我对AS(ActionScript)的一点简单理解
- 我对java IO流简单的理解
- 我对px em rem的简单理解
- 我对SOA的理解我对SOA的理解
- 我对COM的理解
- 我对事件的理解
- 我对SOA的理解
- 我对SOA的理解
- 我对SOA的理解
- Windows CE 6.0 安装顺序
- 关于“操作必须使用一个可更新的查询”错误提示!
- oracle连接配置
- AT+CNMI的使用____by张伟
- apache 安装后No services installed问题
- 我对petshop4的简单理解!
- Hibernate关系映射的说明
- oracle time_zone(zt)
- 删除与恢复扩展存储过程
- 英特尔® 博锐™ 处理器技术
- 查看进程命令
- Flex compiler API指南(第一章)
- java经典题目_之拿来主义1
- 学习笔记三——数组