我对petshop4的简单理解![通俗易懂]

我对petshop4的简单理解![通俗易懂]petshop4充分体现了面向接口编程的思想,就是给你一个接口你别管我是怎么实现的,你只管用别说其他的。namespacePetShop.BLL{   ///   ///Abusinesscomponenttomanageproducts   ///   publicclassProduct{       //Getaninstan

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

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的一些操作串联起来看一遍!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/183808.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Simple Problem with Integers POJ – 3468

    Simple Problem with Integers POJ – 3468

    2021年9月27日
    40
  • initramfs学习「建议收藏」

    initramfs学习「建议收藏」(一)helloworld一、initramfs是什么在2.6版本的linux内核中,都包含一个压缩过的cpio格式的打包文件。当内核启动时,会从这个打包文件中导出文件到内核的rootfs文件系统,然后内核检查rootfs中是否包含有init文件,如果有则执行它,作为PID为1的第一个进程。这个init进程负责启动系统后续的工作,包括定位、挂载“真正的”根文件系统设备(如果有的话)。

    2022年8月11日
    9
  • mysql的乐观锁使用_mysql悲观锁需要注意什么

    mysql的乐观锁使用_mysql悲观锁需要注意什么记得在上大学那会开始,在大学的课堂上,常常会听到老师讲什么共享锁,排它锁各种锁的词汇,以前仅仅听过一次就没有管了,并没有进行深入的研究最近,在各种群里,又看见了什么乐观锁、悲观锁什么鬼的感觉很高级的词汇,于是乎今天对这几个概念进行学习,揭开它神秘的面纱,缕缕思路记录下我对这几个概念的想法实验环境:mysql5.6存储引擎:innoDB我们在操作数据库的时候,可能

    2022年10月8日
    0
  • vector的find用法[通俗易懂]

    vector的find用法[通俗易懂]一.find函数存在于算法中其头文件为#include&lt;algorithm&gt;二.代码示例:#include&lt;vector&gt;#include&lt;algorithm&gt;#include&lt;iostream&gt;usingnamespacestd;intmain(){vector&lt;int&gt;L;L.pu…

    2022年10月10日
    0
  • 微信小程序能跳转到外部链接吗(小程序跳转第三方网页)

    个人类型和海外类型的小程序不支持web-view标签也就是说个人申请的小程序,就别想跳转了!!!!1.开发的时候,我们难免碰到要跳转到其他网页中去那该怎么实现呢?2.例如我想点击一个按钮,跳转到百度(百度的网页还是在小程序中打开)3.wxml1.index.wxml(按钮页面)&lt;viewclass=’wrapper’&gt;&lt;b…

    2022年4月18日
    69
  • 软件测试等价类划分实例_软件测试原则

    软件测试等价类划分实例_软件测试原则等价类的设计思路:根据输入条件,确定等价类,包括有效等价类和无效等价类,建立等价类列表为每个等价类规定一个唯一的编号设计一个测试用例,使其尽可能多地覆盖尚未被覆盖的有效等价类,重复这一步,直到所有的有效等价类被覆盖完为止设计一个测试用例,使其尽可能多的覆盖尚未被覆盖的无效等价类,重复这一步,直到所有的无效等价类被覆盖完为止1、三角形–等价类测试的例子某程序规定:"输入三个整数 a 、 b 、 c…

    2022年8月31日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号