[size=10pt]P[/size] [size=10pt]etshop[font=宋体]采用了典型的三层架构,从下而上为:数据访问层、业务逻辑层、表示层。[/font] [/size]

[size=10pt][b][font=宋体]数据访问层[/font] [/b][/size][size=10pt][font=宋体],其主要功能就是负责数据库的访问,简单的说法就是完成对数据库的增删改查等基本操作。[/font] [/size]

[size=10pt][font=宋体]安装后,有四个数据库,MSPetShop4,MSPetShop4Orders,MSPetShop4Profile,MSPetShop4Services。[/font] [/size]

[size=10pt][b]1[font=宋体]:MSPetShop4[/font] [/b][/size][size=10pt][b][font=宋体]:[/font] [/b][/size]

[img]http://www.cnblogs.com/images/cnblogs_com/sunfishlu/133224/r_1.JPG[/img]
[size=10pt]Product[font=宋体]:宠物商品目录[/font] [/size]

[size=10pt]Category[font=宋体]:宠物类别相关信息[/font] [/size]

[size=10pt]Supplier[font=宋体]:宠物供应商信息[/font] [/size]

[size=10pt]Item[font=宋体]:单个宠物详细信息[/font] [/size]

[size=10pt]Inventory[font=宋体]:宠物库存信息[/font] [/size]

[size=10pt]2[font=宋体]:MSPetShop4Orders[/font] [/size]

[img]http://www.cnblogs.com/images/cnblogs_com/sunfishlu/133224/r_2.JPG[/img]
[size=10pt]Orders[font=宋体]:商品订单详细信息[/font] [/size]

[size=10pt]LineItem[font=宋体]:存储订单中所购买商品的信息[/font] [/size]

[size=10pt]OrderStatus[font=宋体]:记录订单的状态[/font] [/size]

[size=10pt]3[font=宋体]:MSPetShop4Profile[/font] [/size]

[img]http://www.cnblogs.com/images/cnblogs_com/sunfishlu/133224/r_3.JPG[/img]
[size=10pt]Account[font=宋体]:记录客户的基本信息[/font] [/size]

[size=10pt]Profile[font=宋体]:客户活动的基本信息[/font] [/size]

[size=10pt]Cart[font=宋体]:客户购物车和意向清单中的信息[/font] [/size]

[size=10pt]4[font=宋体]:MSPetShop4Services[/font] [/size]

[size=10pt]aspnet_Applications[/size] [size=10pt][font=宋体]:存储数据库所涉及应用程序的有关信息[/font] [/size]

[size=10pt]aspnet_Membership[/size] [size=10pt][font=宋体]:存储与用户有关的信息[/font] [/size]

[size=10pt]DBUtility[/size]

[size=10pt][font=宋体]是数据访问的辅助,其中SqlHelper类图如下[/font] [/size][size=10pt][font=宋体]:[/font] [/size]

[img]http://www.cnblogs.com/images/cnblogs_com/sunfishlu/133224/r_4.JPG[/img]
[size=10pt]CachedParameters[font=宋体]()用于实现命令参数缓存的功能。[/font] [/size]

[size=10pt]GetCachedParameters[font=宋体]()方法用于获取缓存中的命令参数。[/font] [/size]

[size=10pt]ExcuteReader[font=宋体]()用于执行SqlCommand,并返回一个SqlDataReader对象。[/font] [/size]

[size=10pt]ExecuteScalar[font=宋体]()用于执行SQL文本或者存储过程,并返回结果集中第一行的第一列。[/font] [/size]

[size=10pt]PrepareCommand[font=宋体]()用于为执行SQL文本命令和存储过程,而设置SqlCommand相关参数。[/font] [/size]

[size=10pt][font=宋体]在数据访问层中,使用IDAL抽象出数据访问逻辑,并以DALFactory作为数据访问层对象的工厂,IDAL支持SQL Server和Oracle,Model则是业务实体对象。其结构图如下:[/font] [/size]

[img]http://www.cnblogs.com/images/cnblogs_com/sunfishlu/133224/r_5.JPG[/img]

[size=10pt][b][font=宋体]业务逻辑层[/font] [/b][/size][size=10pt][font=宋体],是系统的核心部分,关系到整个系统的业务。通过调用数据访问层,来完成一系列的业务操作。[/font] [/size]

[img]http://www.cnblogs.com/images/cnblogs_com/sunfishlu/133224/r_6.JPG[/img]

[size=10pt][font=宋体]业务实体项目[/font] [/size][size=10pt]Model[/size] [size=10pt][font=宋体]:[/font] [/size]

[size=10pt][font=宋体]业务实体和数据表中无必然的联系,业务实体是综合分析应用程序功能和数据库中的表后的结果。[/font] [/size]

[size=10pt][font=宋体]站点的页面需要加载数据时,表示层向BLL项目发送请求,如:[/font] [/size]

[align=left]
[size=10pt]private[/size]
[size=10pt]void[/size] [size=10pt]BindCategories()[/size]
[/align]
[align=left][size=10pt] {[/size]
[/align]
[align=left]
[size=10pt]Category[/size] [size=10pt]category = [/size][size=10pt]new[/size]
[size=10pt]Category[/size] [size=10pt]();[/size]
[/align]
[align=left][size=10pt] repCategories.DataSource = category.GetCategories();[/size]
[/align]
[align=left][size=10pt] repCategories.DataBind(); [/size]
[/align]
[size=10pt] }[/size]

[size=10pt][font=宋体]然后[/font] [/size][size=10pt]category.GetCategories()[/size] [size=10pt]调用BLL项目中的[/size] [size=10pt]GetCategories()[/size] [size=10pt]方法,[/size]

[align=left][size=10pt]public[/size]
[size=10pt]IList[/size] [size=10pt]<[/size] [size=10pt]CategoryInfo[/size] [size=10pt]> GetCategories()[/size]
[/align]
[align=left][size=10pt] {[/size]
[/align]
[align=left]
[size=10pt]return[/size] [size=10pt]dal.GetCategories();[/size]
[/align]
[size=10pt] }[/size]

[size=10pt]而dal为一个[/size] [size=10pt]ICategory[/size] [size=10pt]接口类型的对象[/size]

[size=10pt]private[/size]
[size=10pt]static[/size]
[size=10pt]readonly[/size]
[size=10pt]ICategory[/size] [size=10pt]dal = PetShop.DALFactory.[/size] [size=10pt]DataAccess[/size] [size=10pt].CreateCategory();[/size]

[size=10pt][b](面向接口编程)。[/b][/size]

[img]http://www.cnblogs.com/images/cnblogs_com/sunfishlu/133224/r_7.JPG[/img]
[size=10pt]Category[/size] [size=10pt]:[/size]

[size=10pt]GetCategories()[/size] [size=10pt]:获取所有宠物类别信息[/size]

[size=10pt]GetCategory([/size] [size=10pt]string[/size] [size=10pt]categoryId)[/size] [size=10pt]:获取单个宠物类别[/size]

[size=10pt]Item[/size] [size=10pt]:[/size]

[size=10pt]GetItem([/size] [size=10pt]string[/size] [size=10pt]itemId)[/size] [size=10pt],[/size] [size=10pt]GetItemsByProduct([/size] [size=10pt]string[/size] [size=10pt]productId)[/size] [size=10pt]:根据不同的参数获得单个宠物信息[/size]

[size=10pt]Inventory[/size] [size=10pt]:[/size]

[size=10pt]CurrentQuantityInStock([/size] [size=10pt]string[/size] [size=10pt]itemId)[/size] [size=10pt]:获取宠物库存数量[/size]

[size=10pt]TakeStock([/size] [size=10pt]LineItemInfo[/size] [size=10pt][] items)[/size] [size=10pt]:更新库存量[/size]

[size=10pt]Product[/size] [size=10pt]:通过不同的参数获得宠物目录信息[/size]

[size=10pt]GetProductsByCategory([/size] [size=10pt]string[/size] [size=10pt]category)[/size] [size=10pt]: [/size]

[size=10pt]GetProductsBySearch([/size] [size=10pt]string[/size] [size=10pt]text)[/size] [size=10pt]:[/size]

[size=10pt]GetProduct([/size] [size=10pt]string[/size] [size=10pt]productId)[/size] [size=10pt]:[/size]

[size=10pt]Cart:[/size]

[size=10pt]Add:向购物车或者意向清单中添加商品[/size]

[size=10pt]Clear:清除购物车或者意向清单中商品[/size]

[size=10pt]GetOrderLineItems:转换类型[/size]

[size=10pt]Remove:根据参数删除商品[/size]

[size=10pt]SetQuantity:更新购物车或者意向清单中的商品数量[/size]

[size=10pt][b][font=宋体]表示层[/font] [/b][/size][size=10pt][font=宋体],[/font] [/size][size=10pt][font=宋体]系统的界面。[/font] [/size]

[size=10pt][b][font=宋体]二:项目列表:[/font] [/b][/size]

[img]http://www.cnblogs.com/images/cnblogs_com/sunfishlu/133224/r_8.JPG[/img]

[size=10pt]1[font=宋体]:BLL 业务逻辑层[/font] [/size]

[size=10pt]2[font=宋体]:CacheDependencyFactory 缓存工厂类[/font] [/size]

[size=10pt]3[font=宋体]:Web 表示层[/font] [/size]

[size=10pt]4[font=宋体]:DALFactory 数据访问层的抽象工厂[/font] [/size]

[size=10pt]5[font=宋体]:DBUtility 数据访问的方法[/font] [/size]

[size=10pt]6[font=宋体]:IBLLStrategy 实现同步异步订单处理功能而定义的[/font] [/size][size=10pt]接口[/size] [size=10pt]IOrderStrategy[/size]

[size=10pt]7:[/size] [size=10pt]ICacheDependency [/size][size=10pt]IPetShopCacheDependency[/size] [size=10pt]接口,实现简单工厂模式中的抽象接口[/size]

[size=10pt]8:IDAL 定义了数据访问层的接口[/size]

[size=10pt]9:IMessaging 定义了订单消息队列的接口[/size]

[size=10pt]10:IProfileDAL 定义了Profile数据访问层接口[/size]

[size=10pt]11:Membership 完成了成员资格管理的数据访问[/size]

[size=10pt]12:MessagingFactory 处理消息队列的抽象工厂[/size]

[size=10pt]13:Model 业务实体类[/size]

[size=10pt]14:MSMQMesageing 实现了IOrder中定义的方法[/size]

[size=10pt]15:OracleDAL Oracle数据访问层[/size]

[size=10pt]16:OracleProfileDAL 数据库为Oracle时,抽象工厂中的具体产品类,实现了IProfileDAL定义的接口成员方法[/size]

[size=10pt]17:[/size] [size=10pt]OrderProcessor[font=宋体]:处理来自消息队列的异步订单[/font] [/size]

[size=10pt]18[font=宋体]:Profile:Profile的数据访问层[/font] [/size]

[size=10pt]19[font=宋体]:ProfileDALFactory:[/font] [/size][size=10pt]ProfileDAL的工厂类[/size]

[size=10pt]20:[/size] [size=10pt]SQLProfileDAL[font=宋体]:[/font] [/size][size=10pt]数据库为SQL Server时,抽象工厂中的具体产品类,实现了IProfileDAL[/size]

[size=10pt]定义的接口成员方法[/size]

[size=10pt]21:[/size] [size=10pt]SQLServerDAL[font=宋体]:[/font] [/size][size=10pt]SQL Server的数据访问层[/size]

[size=10pt]22:[/size] [size=10pt]TableCacheDependency[font=宋体]:缓存依赖的产品类[/font] [/size]

[size=10pt][font=宋体]三:PetShop4中的设计模式[/font] [/size]

[size=10pt]1[font=宋体]:工厂模式:[/font] [/size]

[size=10pt]DALFactory[font=宋体]项目中的DataAccess为工厂类,IDAL项目作为抽象产品接口,而SQLServerDAL则是具体的产品类。[/font] [/size]

[size=10pt][font=宋体]以下利用了反射技术,动态的加载指定类型。[/font] [/size]

[align=left]
[size=10pt]public[/size]
[size=10pt]static[/size] [size=10pt]PetShop.IDAL.[/size] [size=10pt]ICategory[/size] [size=10pt]CreateCategory()[/size]
[/align]
[align=left][size=10pt]{[/size]
[/align]
[align=left]
[size=10pt]string[/size] [size=10pt]className = path + [/size][size=10pt]”.Category”[/size] [size=10pt];[/size]
[/align]
[align=left]
[size=10pt]return[/size] [size=10pt](PetShop.IDAL.[/size] [size=10pt]ICategory[/size] [size=10pt])[/size] [size=10pt]Assembly[/size] [size=10pt].Load(path).CreateInstance(className);[/size]
[/align]
[size=10pt]}[/size]

[size=10pt]2[font=宋体]:策略模式:[/font] [/size]

[size=10pt][font=宋体]策略模式主要是针对一组算法,将每一个算法封装到具有共同接口的独立类中,从而使得它们可以相互替换。[/font] [/size]

[size=10pt][font=宋体]策略模式可以让算法在不影响客户端的情况下发生变化。[/font] [/size]

[size=10pt] BLL[font=宋体]项目中的Order类实现环境角色[/font] [/size]

[size=10pt] IBLLStrategy[font=宋体]项目中IOrderStrategry接口实现抽象策略角色。[/font] [/size]

[size=10pt] BLL[font=宋体]中的OrderSynchronous和OrderAsynchronous实现具体策略角色。
[转]:[url]http://www.cnblogs.com/sunfishlu/archive/2008/02/02/1062049.html[/url]
[/font][/size]

Comments are closed.

Post Navigation