freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

petshop的系統(tǒng)架構(gòu)設(shè)計-資料下載頁

2025-06-29 18:28本頁面
  

【正文】 cy工廠繼承了抽象類TableDependency的Product、Category和Item類均需要在調(diào)用時創(chuàng)建各自的對象。由于它們的父類TableDependency實現(xiàn)了接口IPetShopCacheDependency,因而它們也間接實現(xiàn)了IPetShopCacheDependency接口,這為實現(xiàn)工廠模式提供了前提。在PetShop ,依然利用了配置文件和反射技術(shù)來實現(xiàn)工廠模式。,類DependencyAccess即為創(chuàng)建IPetShopCacheDependency對象的工廠類:public static class DependencyAccess{ public static IPetShopCacheDependency CreateCategoryDependency() { return LoadInstance(”Category”)。 } public static IPetShopCacheDependency CreateProductDependency() { return LoadInstance(”Product”)。 } public static IPetShopCacheDependency CreateItemDependency() { return LoadInstance(”Item”)。 } private static IPetShopCacheDependency LoadInstance(string className) { string path = [”CacheDependencyAssembly”]。 string fullyQualifiedClass = path + “.” + className。 return (IPetShopCacheDependency)(path).CreateInstance(fullyQualifiedClass)。 }}整個工廠模式的實現(xiàn)如圖43所示:圖43 CacheDependency工廠雖然DependencyAccess類創(chuàng)建了實現(xiàn)了IPetShopCacheDependency接口的類Category、Product、Item,然而我們之所以引入IPetShopCacheDependency接口,其目的就在于獲得創(chuàng)建了依賴項的AggregateCacheDependency類型的對象。我們可以調(diào)用對象的接口方法GetDependency(),如下所示:AggregateCacheDependency dependency = ().GetDependency()。為了方便調(diào)用者,似乎我們可以對DependencyAccess類進行改進,將原有的CreateCategoryDependency()方法,修改為創(chuàng)建AggregateCacheDependency類型對象的方法。然而這樣的做法擾亂了作為工廠類的DependencyAccess的本身職責,且創(chuàng)建IPetShopCacheDependency接口對象的行為仍然有可能被調(diào)用者調(diào)用,所以保留原有的DependencyAccess類仍然是有必要的。在PetShop ,是通過引入Facade模式以方便調(diào)用者更加簡單地獲得AggregateCacheDependency類型對象。 引入Facade模式利用Facade模式可以將一些復(fù)雜的邏輯進行包裝,以方便調(diào)用者對這些復(fù)雜邏輯的調(diào)用。就好像提供一個統(tǒng)一的門面一般,將內(nèi)部的子系統(tǒng)封裝起來,統(tǒng)一為一個高層次的接口。一個典型的Facade模式示意圖如下所示:圖44 Facade模式Facade模式的目的并非要引入一個新的功能,而是在現(xiàn)有功能的基礎(chǔ)上提供一個更高層次的抽象,使得調(diào)用者可以直接調(diào)用,而不用關(guān)心內(nèi)部的實現(xiàn)方式。以CacheDependency工廠為例,我們需要為調(diào)用者提供獲得AggregateCacheDependency對象的簡便方法,因而創(chuàng)建了DependencyFacade類:public static class DependencyFacade{ private static readonly string path = [”CacheDependencyAssembly”]。 public static AggregateCacheDependency GetCategoryDependency() { if (!(path)) return ().GetDependency()。 else return null。 } public static AggregateCacheDependency GetProductDependency() { if (!(path)) return ().GetDependency()。 else return null。 } public static AggregateCacheDependency GetItemDependency() { if (!(path)) return ().GetDependency()。 else return null。 }}DependencyFacade類封裝了獲取AggregateCacheDependency類型對象的邏輯,如此一來,調(diào)用者可以調(diào)用相關(guān)方法獲得創(chuàng)建相關(guān)依賴項的AggregateCacheDependency類型對象:AggregateCacheDependency dependency = ()。比起直接調(diào)用DependencyAccess類的GetDependency()方法而言,除了方法更簡單之外,同時它還對CacheDependencyAssembly配置節(jié)進行了判斷,如果其值為空,則返回null對象。,靜態(tài)類WebUtility的GetCategoryName()和GetProductName()方法調(diào)用了DependencyFacade類。例如GetCategoryName()方法:public static string GetCategoryName(string categoryId){ Category category = new Category()。 if (!enableCaching) return (categoryId).Name。 string cacheKey = (CATEGORY_NAME_KEY, categoryId)。 // 檢查緩存中是否存在該數(shù)據(jù)項。 string data = (string)[cacheKey]。 if (data == null) { // 。 int cacheDuration = ([”CategoryCacheDuration”])。 // 如果緩存中不存在該數(shù)據(jù)項,則通過業(yè)務(wù)邏輯層訪問數(shù)據(jù)庫獲取。 data = (categoryId).Name。 // 通過Facade類創(chuàng)建AggregateCacheDependency對象。 AggregateCacheDependency cd = ()。 // 將數(shù)據(jù)項以及AggregateCacheDependency 對象存儲到緩存中。 (cacheKey, data, cd, (cacheDuration), , , null)。 } return data。}GetCategoryName()方法首先會檢查緩存中是否已經(jīng)存在CategoryName數(shù)據(jù)項,如果已經(jīng)存在,就通過緩存直接獲取數(shù)據(jù);否則將通過業(yè)務(wù)邏輯層調(diào)用數(shù)據(jù)訪問層訪問數(shù)據(jù)庫獲得CategoryName,在獲得了CategoryName后,會將新獲取的數(shù)據(jù)連同DependencyFacade類創(chuàng)建的AggregateCacheDependency對象添加到緩存中。WebUtility靜態(tài)類被表示層的許多頁面所調(diào)用,例如Product頁面:public partial class Products : { protected void Page_Load(object sender, EventArgs e) { = ([”categoryId”])。 }}顯示頁面title的邏輯是放在Page_Load事件方法中,因而每次打開該頁面都要執(zhí)行獲取CategoryName的方法。如果沒有采用緩存機制,當Category數(shù)據(jù)較多時,頁面的顯示就會非常緩慢。 引入Proxy模式業(yè)務(wù)邏輯層BLL中與Product、Category、Item有關(guān)的業(yè)務(wù)方法,其實現(xiàn)邏輯是調(diào)用數(shù)據(jù)訪問層(DAL)對象訪問數(shù)據(jù)庫,以獲取相關(guān)數(shù)據(jù)。為了改善系統(tǒng)性能,我們就需要為這些實現(xiàn)方法增加緩存機制的邏輯。當我們操作增加了緩存機制的業(yè)務(wù)對象時,對于調(diào)用者而言,應(yīng)與BLL業(yè)務(wù)對象的調(diào)用保持一致。也即是說,我們需要引入一個新的對象去控制原來的BLL業(yè)務(wù)對象,這個新的對象就是Proxy模式中的代理對象。,PetShop為其建立了代理對象ProductDataProxy,并在GetProductByCategory()等方法中,引入了緩存機制,例如:public static class ProductDataProxy{ private static readonly int productTimeout = ([”ProductCacheDuration”])。 private static readonly bool enableCaching = ([”EnableCaching”])。 public static IListGetProductsByCategory(string category) { Product product = new Product()。 if (!enableCaching) return (category)。 string key = “product_by_category_” + category。 IList data = (IList )[key]。 // Check if the data exists in the data cache if (data == null) { data = (category)。 // Create a AggregateCacheDependency object from the factory AggregateCacheDependency cd = ()。 // Store the output in the data cache, and Add the necessary AggregateCacheDependency object (key, data, cd, (productTimeout), , , null)。 } return data。 }}與業(yè)務(wù)邏輯層Product對象的GetProductsByCategory()方法相比,增加了緩存機制。當緩存內(nèi)不存在相關(guān)數(shù)據(jù)項時,則直接調(diào)用業(yè)務(wù)邏輯層Product的GetProductsByCategory()方法來獲取數(shù)據(jù),并將其與對應(yīng)的AggregateCacheDependency對象一起存儲在緩存中。引入Proxy模式,實現(xiàn)了在緩存級別上對業(yè)務(wù)對象的封裝,增強了對業(yè)務(wù)對象的控制。由于暴露在對象外的方法是一致的,因而對于調(diào)用方而言,調(diào)用代理對象與真實對象并沒有實質(zhì)的區(qū)別。從職責分離與分層設(shè)計的角度分析,我更希望這些Proxy對象是被定義在業(yè)務(wù)邏輯層中,而不像在PetShop的設(shè)計那樣,被劃分到表示層UI中。此外,如果需要考
點擊復(fù)制文檔內(nèi)容
范文總結(jié)相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1