网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 
中国网管联盟
Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道
 当前位置: > bitsCN.com > DotNet > .NET框架 > petshop4体现的面向接口编程思想  

petshop4体现的面向接口编程思想

2008-06-26  作者:bitsCN整理  来源:中国网管联盟  点评 投稿 收藏

        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();
中国网管联盟bitsCN.com

        在bll层,这里使用创建Produce的接口,你只管调用他的方法。

        namespace PetShop.IDAL
        {
        /// <summary>
        /// Interface for the Product DAL
        /// </summary> 网管下载dl.bitscn.com

        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> 网管u家u.bitscn@com
        /// <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); } 网管下载dl.bitscn.com

网管下载dl.bitscn.com

        这里是定义了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";
网管网www.bitscn.com

        /// <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>();
网管联盟bitsCN_com

        这里是实现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); }
网管联盟bitsCN@com

        这里是利用工厂模式来映射你需要你想创建哪一个。 网管网www_bitscn_com

        后面还有一些消息队列MSMQMessage利用cache缓存以后达到异步处理购物车里订单的功能! 网管网www.bitscn.com

        刚开始看应先从先从Product入口,关于Product的一些操作串联起来看一遍!

网管u家u.bitscn@com


TAGs
 上一篇:从进程得到该进程关联图标的方法   下一篇:观察者模式 The Observer Pattern
petshop4体现的面向接口编程思想 评论:
loading.. 评论加载中…
评论:请自觉遵守互联网相关政策法规,评论不得超过250字。

验证码: 注册用户
本类热门排行:
最新推荐文章:
网管论坛交流: