架構(gòu)與其他模式_第1頁
架構(gòu)與其他模式_第2頁
架構(gòu)與其他模式_第3頁
架構(gòu)與其他模式_第4頁
架構(gòu)與其他模式_第5頁
已閱讀5頁,還剩72頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、Shanghai Jiaotong UniversityCao JianCIT Lab, Shanghai Jiaotong UniversityShanghai Jiaotong Universityw架構(gòu)分析架構(gòu)分析w邏輯結(jié)構(gòu)精化與分層模式邏輯結(jié)構(gòu)精化與分層模式w其它模式其它模式2022-4-132Shanghai Jiaotong Universityw降低在系統(tǒng)設計中丟失某些重要因素的風險降低在系統(tǒng)設計中丟失某些重要因素的風險w避免在低優(yōu)先級的問題上花費過多的精力避免在低優(yōu)先級的問題上花費過多的精力w有助于產(chǎn)品與業(yè)務目標的一致有助于產(chǎn)品與業(yè)務目標的一致2022-4-133Shangha

2、i Jiaotong Universityw早期工作中就要識別和解決架構(gòu)問題早期工作中就要識別和解決架構(gòu)問題w架構(gòu)分析和早期開發(fā)活動并行架構(gòu)分析和早期開發(fā)活動并行2022-4-134Shanghai Jiaotong Universityw變化點:當前現(xiàn)有系統(tǒng)或需求中的變化之處變化點:當前現(xiàn)有系統(tǒng)或需求中的變化之處w進化點:現(xiàn)有需求中不存在,但可能在將來發(fā)生,進化點:現(xiàn)有需求中不存在,但可能在將來發(fā)生,推測性的變化點推測性的變化點2022-4-135Shanghai Jiaotong Universityw架構(gòu)分析架構(gòu)分析是在功能性需求(例如銷售處理)的語是在功能性需求(例如銷售處理)的語境中

3、,識別和處理系統(tǒng)的非功能性需求(例如安境中,識別和處理系統(tǒng)的非功能性需求(例如安全需求等)的活動。全需求等)的活動。2022-4-136Shanghai Jiaotong Universityw問題示例問題示例n可靠性和容錯需求如何影響設計可靠性和容錯需求如何影響設計n采購子構(gòu)件的許可費用如何影響收益率采購子構(gòu)件的許可費用如何影響收益率n可適應性和可配置性需求如何影響設計可適應性和可配置性需求如何影響設計n商標名稱的選擇如何影響架構(gòu)商標名稱的選擇如何影響架構(gòu)2022-4-137Shanghai Jiaotong Universityw識別和分析對架構(gòu)有影響的非功能性需求識別和分析對架構(gòu)有影響的

4、非功能性需求w對于這些在架構(gòu)方面具有重要影響的需求,需要對于這些在架構(gòu)方面具有重要影響的需求,需要分析可供選擇的辦法并創(chuàng)建解決這些影響的解決分析可供選擇的辦法并創(chuàng)建解決這些影響的解決方案方案架構(gòu)決策架構(gòu)決策2022-4-138Shanghai Jiaotong Universityw所有的所有的FURPS+需求對系統(tǒng)的架構(gòu)都有重要影響,需求對系統(tǒng)的架構(gòu)都有重要影響,其中涉及可靠性,進度安排,技巧和成本約束等其中涉及可靠性,進度安排,技巧和成本約束等w具有架構(gòu)意義的因素稱為具有架構(gòu)意義的因素稱為關(guān)鍵架構(gòu)因素關(guān)鍵架構(gòu)因素2022-4-139Shanghai Jiaotong Universityw

5、描述方法描述方法n質(zhì)量場景:質(zhì)量場景:w當銷售完成當銷售完成,調(diào)用遠程稅金計算器服務計算稅金時,在平均負調(diào)用遠程稅金計算器服務計算稅金時,在平均負載條件的生產(chǎn)環(huán)境下,大部分會在載條件的生產(chǎn)環(huán)境下,大部分會在2秒之內(nèi)返回秒之內(nèi)返回n架構(gòu)因素表(架構(gòu)因素表(P394)w包括因素,度量和質(zhì)量場景,可變性,影響,對于成功的優(yōu)包括因素,度量和質(zhì)量場景,可變性,影響,對于成功的優(yōu)先級,困難或風險先級,困難或風險2022-4-1310Shanghai Jiaotong Universityw收集和組織有關(guān)的架構(gòu)性因素,稱為收集和組織有關(guān)的架構(gòu)性因素,稱為架構(gòu)的科學架構(gòu)的科學w依據(jù)相互依賴情況,優(yōu)先級,權(quán)衡考

6、慮等,做出依據(jù)相互依賴情況,優(yōu)先級,權(quán)衡考慮等,做出解決這些因素的決定,稱為解決這些因素的決定,稱為架構(gòu)的藝術(shù)架構(gòu)的藝術(shù)2022-4-1311Shanghai Jiaotong Universityw記錄架構(gòu)選擇,決策以及動機記錄架構(gòu)選擇,決策以及動機n技術(shù)備忘錄技術(shù)備忘錄w優(yōu)先級優(yōu)先級n引導架構(gòu)決策的目標:強制性約束,業(yè)務目標,所有引導架構(gòu)決策的目標:強制性約束,業(yè)務目標,所有其它目標其它目標w基本的架構(gòu)設計原則基本的架構(gòu)設計原則n我們已經(jīng)介紹的原則都適用:低耦合,高內(nèi)聚,防止我們已經(jīng)介紹的原則都適用:低耦合,高內(nèi)聚,防止變異變異n構(gòu)件的粒度更大構(gòu)件的粒度更大2022-4-1312Shang

7、hai Jiaotong UniversityShanghai Jiaotong Universityw運用分層模式,對系統(tǒng)進行層和分塊邏輯體系結(jié)運用分層模式,對系統(tǒng)進行層和分塊邏輯體系結(jié)構(gòu)設計構(gòu)設計w運用運用UML包圖表示邏輯結(jié)構(gòu)包圖表示邏輯結(jié)構(gòu)w運用外觀,觀察者和控制器模式運用外觀,觀察者和控制器模式2022-4-1314Shanghai Jiaotong Universityw模式分類模式分類n架構(gòu)模式架構(gòu)模式w大范圍和粗粒度的設計:分層模式大范圍和粗粒度的設計:分層模式n設計模式設計模式w與小范圍和中等范圍的對象和框架設計有關(guān)與小范圍和中等范圍的對象和框架設計有關(guān): Faade, St

8、rategy PatternnIdiomswLanguage or implementation-oriented low-level design solutions: Singleton pattern2022-4-1315Shanghai Jiaotong UniversityShanghai Jiaotong Universityw在應用中,哪一個部分最容易改變在應用中,哪一個部分最容易改變?nInterface?nApplication logic?2022-4-1317Shanghai Jiaotong Universityw將大型系統(tǒng)的邏輯結(jié)構(gòu)分成具有各個包含內(nèi)部相將大型系統(tǒng)的邏

9、輯結(jié)構(gòu)分成具有各個包含內(nèi)部相關(guān)責任的層關(guān)責任的層. w層內(nèi)耦合層內(nèi)耦合2022-4-1318Shanghai Jiaotong UniversityPresentation(AKA Interface, UI, View)Application(AKA Workflow, Process,Mediation, App Controller)Domain(s)(AKA Business,Business Services, Model)Technical Services(AKA Technical Infrastructure,High-level Technical Services)Fou

10、ndation(AKA Core Services, Base Services,Low-level Technical Services/Infrastructure)GUI windowsreportsspeech interfaceHTML, XML, XSLT, JSP, Javascript, .handles presentation layer requestsworkflowsession statewindow/page transitionsconsolidation/transformation of disparatedata for presentationhandl

11、es application layer requestsimplementation of domain rulesdomain services (POS , Inventory )- services may be used by just oneapplication, but there is also the possibilityof multi-application services(relatively) high-level technical servicesand frameworksPersistence, Securitylow-level technical s

12、ervices, utilities,and frameworksdata structures, threads, math,file, DB, and network I/OmoreappspecificBusiness Infrastructure(AKA Low-level Business Services)very general low-level business servicesused in many business domainsCurrencyConverter2022-4-1319Shanghai Jiaotong University2022-4-1320Log4

13、JTechnical ServicesDomainPresentationPricingPricingStrategyFactoryTextProcessSaleConsoleused in quickexperimentsPersistenceDBFacadeinterfaceISalePricingStrategyTaxesinterfaceITaxCalculatorAdapterServicesFactorySalesRegisterSaleSwingProcessSaleFramePaymentsCreditPaymentinterfaceICreditAuthorizationSe

14、rviceAdapterServiceAccessInventoryinterfaceIInventoryAdapterJessA generalpurpose third-party rulesengine.POSRuleEnginePOSRuleEngineFacadeSOAPnot the JavaSwing libraries, butour GUI classesbased on SwingShanghai Jiaotong University2022-4-1321Log4JTechnical ServicesDomainPresentationPricingPersistence

15、DBFacadeTaxesinterfaceITaxCalculatorAdapterServicesFactorySalesRegisterSaleSwingProcessSaleFramePaymentsCreditPaymentinterfaceICreditAuthorizationServiceAdapterServiceAccessInventoryinterfaceIInventoryAdapterJessPOSRuleEnginePOSRuleEngineFacadeSOAPShanghai Jiaotong University2022-4-1322Log4JTechnica

16、l ServicesDomainPresentationJessPersistencePOSRuleEngineInventoryPaymentsServiceAccessPricingSalesTextSwingSOAPHide the specific types and focus on illustrating the package-package couplingShanghai Jiaotong University2022-4-1323: Domain:Sales:Register:Cashier: Presentation:Swing:ProcessSaleFrameente

17、rItem(id, qty)singleton: Tech-Services:Persistence:Persistence-Facadespec :=getProductSpec(id)x := isInvalid(lineItem, sale)spec := getObject(.,id)singleton: Domain:POSRule-Engine:POSRule-EngineFacadeenterItem(id, qty)s :Domain:Sales:Sale: Domain:Products:ProductCatalogmakeLineItem(spec, qty)subsyst

18、em: Tech-Services:JesssomeJessCalls(lineItem, sale)Points of crossing interesting boundaries or layers. These are especially noteworthy for people who need tounderstand the system, and thus are highlighted in this diagram. This diagram supports communicating thelogical view of the architecture (a UP

19、 term) because it emphasizes architecturally significant information.UML notation: Note that a subsytem can be modeled as an object in the UML.This is useful in this case where I dont know or want to describe the details of how theJess rule engine works, but just want to show collaboration with it.U

20、ML notation: UML pathname to indicate packagingonPropertyEvent(s, sale.total, total)PropertyListenerShanghai Jiaotong Universityw某些包就是子系統(tǒng)某些包就是子系統(tǒng)nPersistence, POSRuleEngine,w某些包只是對象集合某些包只是對象集合nPricing Package2022-4-1324Shanghai Jiaotong Universityw訪問代表子系統(tǒng)的包的訪問代表子系統(tǒng)的包的方法最常用的模式就是方法最常用的模式就是外觀模式外觀模式w外觀一

21、般不能暴露太多外觀一般不能暴露太多的低層操作的低層操作w外觀經(jīng)常是下層子系統(tǒng)外觀經(jīng)常是下層子系統(tǒng)對象的協(xié)調(diào)器對象的協(xié)調(diào)器2022-4-1325subsystemPersistenceDBFacadesubsystemJesssubsystemPOSRuleEnginePOSRuleEngineFacadePricingnot a subsystemShanghai Jiaotong UniversityLog4JTechnical ServicesDomainPresentationPersistenceDBFacadeSalesRegisterSaleSwingProcessSaleFram

22、eJessSOAPfor applications with only a few systemoperations, perhaps only one object acts as thefacade into the layerThe Technical Services layertypically exposes manyinterfaces-at least one persubsystem2022-4-1326Shanghai Jiaotong University2022-4-1327ApplicationDomainPresentationSalesRegisterSaleSw

23、ingProcessSaleFrameApplication sessionfacade objects thatmaintain sessionstate and controlworkflow related tosome work-oftenby use case.ProcessSaleSessionFacadeProcessRentalSessionFacadeHandleReturnsSessionFacadeProcessRentalFrame.RentalsRental.Shanghai Jiaotong University2022-4-1328DomainPresentati

24、onSwingProcessSaleFrame.RegistermakeNewSale()enterItem().: CashiermakeNewSale()enterItem()endSale()makeNewSale()enterItem()endSale()enterItem(id, quantity):System: CashierendSale()description, total* more itemsmakeNewSale()the system operations handled by the system in an SSD represent theoperation

25、calls on the Application or Domain layer from the Presentation layerShanghai Jiaotong University2022-4-1329Domain(s)TechnicalServicesFoundationInventoryPersistenceNaming andDirectory ServicesWebAppFrameworkTechnical ServicesPOSInventoryDomain(s)FoundationWorsemixes logical and implementation viewsBe

26、ttera logical viewa logical representationof the need for data orservices related to thesesubdomains, abstractingimplementation decisionssuch as a database.NovellLDAPUML notation: A UML component, or physical part of the system.UML notation: A physical database in the UML.Shanghai Jiaotong Universit

27、y2022-4-1330: Domain:Sales:Register:Cashier: Presentation:Swing:ProcessSaleFrameenterItem(id, qty).enterItem(id, qty)s :Domain:Sales:SalemakeLineItem(spec, qty)Collaboration from the lower layers to the Presentation layer is usually via the Observer (Publish-Subscribe)pattern. The Sale object has re

28、gistered subscribers that are PropertyListeners. One happens to be a SwingGUI JFrame, but the Sale does not know this object as a GUI JFrame, but only as a PropertyListener.onPropertyEvent(s, sale.total, total)PropertyListener.Shanghai Jiaotong Universityw某些情況下,增加層次將引入性能問題某些情況下,增加層次將引入性能問題w并不是適用于所有問

29、題并不是適用于所有問題nFor example, Pipes and Filters2022-4-1331Shanghai Jiaotong Universityw關(guān)注點分離關(guān)注點分離Separation of concerns-降低耦合和降低耦合和依賴,提高內(nèi)聚,增加重用性和清晰度依賴,提高內(nèi)聚,增加重用性和清晰度w相關(guān)的復雜性被封裝和分解相關(guān)的復雜性被封裝和分解w低層包含了可重用的功能低層包含了可重用的功能w某些層可以分布某些層可以分布w團隊開發(fā)團隊開發(fā)2022-4-1332Shanghai Jiaotong UniversitywInterfacewApplication LogicwS

30、torageCalculate taxesInterfaceApplicationLogicAuthorizepaymentsStorageDatabase2022-4-1333Shanghai Jiaotong University2022-4-1334calculatetaxesApplicationLogicInterfacecalculatetaxesApplicationLogicInterfaceclassic 3-tier architecture deployedon 2 nodes: thicker clientclassic 3-tier architecturedeplo

31、yed on 3 nodes: thiner clientUML notation:a node. This isa processingresource suchas a computer.Shanghai Jiaotong Universityw模型模型: 領(lǐng)域?qū)訉ο箢I(lǐng)域?qū)訉ο體視圖視圖: 表現(xiàn)對象表現(xiàn)對象, 例如例如windows, applets and reportsw模型(領(lǐng)域)對象不能夠直接知道視圖(表現(xiàn))模型(領(lǐng)域)對象不能夠直接知道視圖(表現(xiàn))對象對象2022-4-1335Shanghai Jiaotong Universityw從上面拉從上面拉Pull-from-above

32、w從下面推從下面推Push-from-belown觀察者模式觀察者模式Observer Pattern: making the GUI object appears as an object implements an interface such as PropertyListenernUI外觀對象外觀對象Presentation faade object2022-4-1336adds a level of indirection toDomainPresentationRegisterSaleProcessSaleFrameUIFacadeUIFacades areoccasionally

33、 used whena push-from-belowcommunication model isrequired.Not a Swing or GUI class.Just a plain object whichthe GUI objectsShanghai Jiaotong UniversityShanghai Jiaotong Universityw使用模式解決某些實際問題使用模式解決某些實際問題:nReliability and recoveryLocal cachingHandling failurenHandling paymentsw7個新模式個新模式2022-4-1338Sh

34、anghai Jiaotong University2022-4-1339IProductsAdaptergetSpecification( itemID ) : ProductSpecificationDBProductsAdaptergetSpecification( itemID )LocalProductsremoteProductsService: IProductAdaptergetSpecification( itemID )BigWebServiceProductsAdaptergetSpecification( itemID )11Implements the adapter

35、interface, but is not reallyan adapter for a secondcomponent.Rather, it itself implementsthe local service function.ProductCatalogproductsService : IProductAdaptergetSpecification()11Shanghai Jiaotong University2022-4-1340:Store:Registerpc:ProductCatalogcreate()2: create(pc)1: create():ServicesFacto

36、rypsa : LocalProductsexternalService :DBProductsAdapter1.1: psa := getProductsAdapter()IProductsAdapter1.1.2: create( externalService )1.1.1: create()本地服務獲取了對外部服務的適配器的引用IProductsAdapter返回本地服務Shanghai Jiaotong University2022-4-1341: LocalProducts remoteService :DBProductsAdapterIProductsAdapter: KeyI

37、ndexedFileOfSerializedObjects1: ps := get( id )3 not in file : put( id, ps )ps := getSpecification(id)2 not in file :ps := getSpecification(id)continued in anotherdiagramIProductsAdapterShanghai Jiaotong Universityw本地緩存中未命中且訪問外部產(chǎn)品服務失敗時,本地緩存中未命中且訪問外部產(chǎn)品服務失敗時,如何處理如何處理?n用信號通知收銀員人工輸入價格和描述用信號通知收銀員人工輸入價格和描

38、述?n取消輸入該商品項取消輸入該商品項?w解決方案解決方案: 拋出異常拋出異常n低層的異常轉(zhuǎn)換成高層次中有意義的異常低層的異常轉(zhuǎn)換成高層次中有意義的異常n依據(jù)問題而不是拋出者命名異常依據(jù)問題而不是拋出者命名異常2022-4-1342Shanghai Jiaotong University2022-4-1343DBUnavailableException(): DBProductsAdapterIProductsAdapter: PersistenceFacadeUML notation:*All asynchronous messages, including exceptions, are

39、illustrated with a stickarrowhead.*Exceptions are shown as messages indicated by the exception class name.*An optional or stereotype is legal (an exception isa kind of signal in the UML), if increased visibility is desired.ps := get(.)ps := getSpecification(id): Objectjava.sql.StatementresultSet :=

40、executeQuery(.)SQLException()note the difference betweensynchronous and asynchronousmessage arrowheads in the UMLrecall that indicating the instance of type Object is useful when one wants toindicate the interface, but not the class of an instanceProductInfoUnavailableException()stopping the message

41、 lineat this point indicates thePersistenceFacade objectis catching the exceptionShanghai Jiaotong University2022-4-1344exceptions caughtare modeled as akind of operationhandling a signalPersistenceFacadeusageStatistics : MapObject get(Key, Class) throws DBUnavailableException, FatalExceptionput(Key

42、, Object) throws= (DBUnavailableException, FatalException) .玸ignal?SQLException()玸ignal?IOException()exceptionsFatalExceptionDBUnavailableExceptionexceptions throwncan be listed inanothercompartmentlabeledexceptionsUML notation : The UML has a default syntax for operations. But it does not include a

43、n officialsolution to show exceptions thrown by an operation. There are at least three solutions:1. The UML allows the operation syntax to be any other language, such as Java. In addition,some UML CASE tools allow display of operations explicitly in Java syntax.Thus, Object get(Key, Class) throws DB

44、UnavailableException, FatalException2. The default syntax allows the last element to be a property string. This is a list of arbitraryproperty+value pairs, such as author=Craig, kids=(Hannah, Haley), . Thus, put(Object, id) throws= (DBUnavailableException, FatalException) 3. Some UML CASE tools allo

45、w one to specify (in a special dialog box) the exceptions that anoperation throws.Shanghai Jiaotong Universityw轉(zhuǎn)換異常轉(zhuǎn)換異常w對問題而不是拋出者命名對問題而不是拋出者命名w集中錯誤日志集中錯誤日志w錯誤會話錯誤會話w代理代理w抽象工廠抽象工廠w自力更生自力更生2022-4-1345Shanghai Jiaotong Universityw將較低層的異常轉(zhuǎn)換為本層次系統(tǒng)中有意義的異將較低層的異常轉(zhuǎn)換為本層次系統(tǒng)中有意義的異常常n通過轉(zhuǎn)換,高層次的異常提供了對低層次異常的子系通過轉(zhuǎn)換,

46、高層次的異常提供了對低層次異常的子系統(tǒng)層次的解釋統(tǒng)層次的解釋2022-4-1346Shanghai Jiaotong Universityw異常必須依據(jù)其拋出的理由進行命名異常必須依據(jù)其拋出的理由進行命名w拋出者并不能表示問題所在拋出者并不能表示問題所在2022-4-1347Shanghai Jiaotong Universityw使用單實例類訪問的集中錯誤日志對象,所有的使用單實例類訪問的集中錯誤日志對象,所有的異常都向它匯報異常都向它匯報n提供了一致性提供了一致性n對輸出流和格式的柔性定義對輸出流和格式的柔性定義2022-4-1348Shanghai Jiaotong University

47、w使用標準的單實例類訪問的、應用程序無關(guān)的、使用標準的單實例類訪問的、應用程序無關(guān)的、非用戶界面的對象向用戶通知錯誤。非用戶界面的對象向用戶通知錯誤。n對輸出機制的變化實現(xiàn)了防止變異對輸出機制的變化實現(xiàn)了防止變異n一致的錯誤匯報風格一致的錯誤匯報風格n集中控制公共的錯誤通知策略集中控制公共的錯誤通知策略n性能也有所改進性能也有所改進2022-4-1349Shanghai Jiaotong University2022-4-1350: DBProductsAdapter: LocalProductsIProductsAdapter:ProductCatalogps :=getSpec(id):R

48、egisterenterItem(id, qty):ProcessSaleFrameProductInfoUnavailableException():ErrorDialognotify(message, exception)ps :=getSpec(id)ps :=getSpec(id)continued:ErrorDialognotify(message, exception)* : notify(message): Object: ObjectINotifier-GUI dialog box-text console dialog-speech dialog:Loglog(excepti

49、on)IProductsAdapterConvertExceptionpatternError DialogpatternCentralizedError LoggingpatternShanghai Jiaotong Universityw問題問題: 不希望或不可能直接訪問真正的主題對象不希望或不可能直接訪問真正的主題對象時,應該如何時,應該如何w解決方案解決方案: 通過代理對象增加一層間接性,代理通過代理對象增加一層間接性,代理對象實現(xiàn)與主題對象相同的接口,并且負責控制對象實現(xiàn)與主題對象相同的接口,并且負責控制和增強對主題對象的訪問和增強對主題對象的訪問2022-4-1351Shangha

50、i Jiaotong University2022-4-1352ISubjectInterfacefoo()RealSubjectfoo(). pre-processingrealSubject.foo(). post-processingClientsubject : ISubjectInterfacedoBar()1111ProxyrealSubject : ISubjectInterfacefoo(). whateversubject.foo(). whateversubject actuallyreferences aninstance of Proxy,not RealSubject

51、realSubject will actually reference aninstance of RealSubjectShanghai Jiaotong Universityw可能需要與多種不同的物理設備打交道可能需要與多種不同的物理設備打交道,w這些設備可能來自不同的廠商,如這些設備可能來自不同的廠商,如IBM, Epson, 它們的驅(qū)動十分類似它們的驅(qū)動十分類似 (Java Classes)w問題問題: 如何創(chuàng)建實現(xiàn)相同接口的相關(guān)類的族如何創(chuàng)建實現(xiàn)相同接口的相關(guān)類的族?w解決方案解決方案: 定義一個公共接口定義一個公共接口 (abstract factory), 具體的工廠繼承它具體的

52、工廠繼承它2022-4-1353Shanghai Jiaotong University2022-4-1354IJavaPOSDevicesFactorygetNewCashDrawer() : jpos.CashDrawergetNewCoinDispenser() : jpos.CoinDispenser.IBMJavaPOSDevicesFactory.getNewCashDrawer() : jpos.CashDrawergetNewCoinDispenser() : jpos.CoinDispenser.return new com.ibm.pos.jpos.CashDrawer()

53、jpos.CashDrawerisDrawerOpened().NCRJavaPOSDevicesFactory.getNewCashDrawer() : jpos.CashDrawergetNewCoinDispenser() : jpos.CoinDispenser.return new com.ncr.posdevices.CashDrawer()this is the AbstractFactory-an interface forcreating a family ofrelated objectscom.ibm.pos.jpos.CashDrawerisDrawerOpened()

54、.com.ncr.posdevices.CashDrawerisDrawerOpened().Shanghai Jiaotong Universityw我是對實際對象的抽象,由我來完成這些通常由我是對實際對象的抽象,由我來完成這些通常由實際對象完成的事情實際對象完成的事情w與信息專家模式相比較與信息專家模式相比較 (Text Object does spell-checking), 多態(tài)多態(tài) (Circle Object draws itself)2022-4-1355Shanghai Jiaotong University2022-4-1356Paymentamountauthorize()

55、CashPaymentauthorize()CreditPaymentauthorize()CheckPaymentauthorize()DebitPaymentauthorize()By Polymorphism, each payment type should authorize itself.This is also in the spirit of Do it Myself (Coad)Shanghai Jiaotong Universityw采用模式來設計持久化框架采用模式來設計持久化框架w某些與數(shù)據(jù)處理相關(guān)的模式某些與數(shù)據(jù)處理相關(guān)的模式:將對象表示為表將對象表示為表Represe

56、nting object relationships as Tables 對象標識對象標識數(shù)據(jù)庫映射器數(shù)據(jù)庫映射器Database Mapper/Broker緩存管理緩存管理Cache managementw新的新的GoF 模式模式: Template, State, Command, Virtual Proxy2022-4-1357Shanghai Jiaotong UniversitywWhat is a persistence service?wWhat is a framework?wBasic requirements of a persistence service:nStore

57、and retrieve objectsnCommit and rollback2022-4-1358Shanghai Jiaotong UniversitywSchema wMapping (between class and persistent store)wObject identitywMaterialization and dematerializationwCachingwTransaction statewLazy materialization2022-4-1359Shanghai Jiaotong UniversitywSolution (Representing obje

58、cts as tables): define a table for each persistent classwEach attribute becomes a columnwNew problem: How to deal with complex attributes (see “Representing object relationships as Tables”)2022-4-1360Shanghai Jiaotong University2022-4-1361McityNow&ZenMumbaiMANUFACTURER TA

59、BLE: Manufacturername = Now&Zencity = MumbaiCelestialShorteningSan RamonShanghai Jiaotong UniversitywSolution: Define an object identifier (OID) for each object, and put the OID in corresponding row of table2022-4-1362Shanghai Jiaotong University2022-4-1363OIDxyz123abc345This is a simplified des

60、ign.In reality, the OID may beplaced in a Proxy class.primary keyManufacturercitynameoid : OID.namecityNow&ZenMumbaiMANUFACTURER TABLE: Manufacturercity = Mumbainame = Now&Zenoid = xyz123CelestialShorteningSan RamonShanghai Jiaotong UniversitywInfo expert suggests the object should do this itself (i.e. di

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論