【正文】
e] : ps := getSpecification(id) continued in another diagram IProductsAdapter Shanghai Jiaotong University 處理故障 ?本地緩存中未命中且訪問外部產(chǎn)品服務(wù)失敗時,如何處理 ? ? 用信號通知收銀員人工輸入價格和描述 ? ? 取消輸入該商品項 ? ?解決方案 : 拋出異常 ? 低層的異常轉(zhuǎn)換成高層次中有意義的異常 ? 依據(jù)問題而不是拋出者命名異常 2020/11/4 42 Shanghai Jiaotong University 處理錯誤 (seq diagram) 2020/11/4 43 exception DBUnavailableException() : DBProducts Adapter IProductsAdapter : Persistence Facade UML notation : * All asynchronous messages, including exceptions, are illustrated with a stick arrowhead. * Exceptions are shown as messages indicated by the exception class name. * An optional exception or signal stereotype is legal (an exception is a kind of signal in the UML), if increased visibility is desired. ps := get(...) ps := getSpecification(id) : Object resultSet := executeQuery(...) exception SQLException() note the difference between synchronous and asynchronous message arrowheads in the UML recall that indicating the instance of type Object is useful when one wants to indicate the interface, but not the class of an instance exception ProductInfoUnavailableException() stopping the message line at this point indicates the PersistenceFacade object is catching the exception Shanghai Jiaotong University Exceptions in a UML class diagram 2020/11/4 44 exceptions caught are modeled as a kind of operation handling a signal PersistenceFacade usageStatistics : Map Object get(Key, Class) throws DBUnavailableException, FatalException put(Key, Object) { throws= (DBUnavailableException, FatalException) } ... 玸 ignal?SQLException() 玸 ignal?IOException() exceptions FatalException DBUnavailableException exceptions thrown can be listed in another partment labeled exceptions UML notation : The UML has a default syntax for operations. But it does not include an official solution 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 , Object get(Key, Class) throws DBUnavailableException, FatalException 2. The default syntax allows the last element to be a property string. This is a list of arbitrary property+value pairs, such as { author=Craig, kids=(Hannah, Haley), ...}. Thus, put(Object, id) { throws= (DBUnavailableException, FatalException) } 3. Some UML CASE tools allow one to specify (in a special dialog box) the exceptions that an operation throws. Shanghai Jiaotong University 更多模式 ?轉(zhuǎn)換異常 ?對問題而不是拋出者命名 ?集中錯誤日志 ?錯誤會話 ?代理 ?抽象工廠 ?自力更生 2020/11/4 45 Shanghai Jiaotong University (1)轉(zhuǎn)換異常 ?將較低層的異常轉(zhuǎn)換為本層次系統(tǒng)中有意義的異常 ? 通過轉(zhuǎn)換,高層次的異常提供了對低層次異常的子系統(tǒng)層次的解釋 2020/11/4 46 Shanghai Jiaotong University (2)命名問題,而不是拋出者 ?異常必須依據(jù)其拋出的理由進行命名 ?拋出者并不能表示問題所在 2020/11/4 47 Shanghai Jiaotong University (3)集中錯誤日志 ?使用單實例類訪問的集中錯誤日志對象,所有的異常都向它匯報 ? 提供了一致性 ? 對輸出流和格式的柔性定義 2020/11/4 48 Shanghai Jiaotong University (4)錯誤會話 ?使用標準的單實例類訪問的、應(yīng)用程序無關(guān)的、非用戶界面的對象向用戶通知錯誤。subsystem187。subsystem187。subsystem187。 : Tech Services ::Jess someJessCalls(lineItem, sale) Points of crossing interesting boundaries or layers. These are especially noteworthy for people who need to understand the system, and thus are highlighted in this diagram. This diagram supports municating the l ogical view of the architecture (a UP 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 don39。 : Domain:: POSRule Engine:: POSRule Engine Facade enterItem (id, qty) s : Domain:: Sales:: Sale : Domain:: Products:: Product Catalog makeLineItem(spec, qty) 171。 : Tech Services:: Persistence:: Persistence Facade spec := getProduct Spec(id) x := isInvalid (lineItem, sale) spec := getObject(...,id) 171。 IInventoryAdapter Jess POSRuleEngine POSRuleEngineFacade SOAP Shanghai Jiaotong University 2020/11/4 22 Log4J Technical Services Domain Presentation Jess Persistence POSRuleEngine Inventory Payments ServiceAccess Pricing Sales Text Swing SOAP Hide the specific types and focus on illustrating the packagepackage coupling Shanghai Jiaotong University 層內(nèi)和包間交互場景 2020/11/4 23 : Domain:: Sales:: Register :Cashier : Presentation:: Swing:: Process SaleFrame enterItem (id, qty) 171。 ICreditAuthorization ServiceAdapter ServiceAccess Inventory 171。 ITaxCalculatorAdapter Services Factory Sales Register Sale Swing ProcessSale Frame Payments CreditPayment 171。 IInventoryAdapter Jess A general purpose third party rules engine. POSRuleEngine POSRuleEngineFacade SOAP not the Java Swing libraries, but our GUI classes based on Swing Shanghai Jiaotong University 層內(nèi)耦合和包間耦合 2020/11/4 21 Log4J Technical Services Domain Presentation Pricing Persistence DBFacade Taxes 171。 ICreditAuthorization ServiceAdapter ServiceAccess Inventory 171。 ITaxCalculatorAdapter Services Factory Sales Register Sale Swing ProcessSale Frame Payments CreditPayment 171。 ISalePricingStrategy Taxes 171。ade, Strategy Pattern ? Idioms ? Language or implementationoriented lowlevel design solutions: Singleton pattern 2020/11/4 15 Shanghai Jiaotong University : 分層 Shanghai Jiaotong University (1)問題 ?在應(yīng)用中,哪一個部分最容易改變 ? ? Interface? ? Application logic? 2020/11/4 17 Shanghai Jiaotong University (2)解決方案 ?將大型系統(tǒng)的邏輯結(jié)構(gòu)分成具有各個包含內(nèi)部相關(guān)責(zé)任的層 . ?層內(nèi)耦合 2020/11/4 18 Shanghai Jiaotong University Pr e sen ta ti on( A K A I n t e r f a c e , U I , V i e w )A p p l i ca ti o n(