1 / 47

廖峻鋒 Aug 22,2003 NCCU Computer Center

UML-F tags for Framework Construction Principles and Patterns - The UML Profile for Framework Architectures 讀書會第四章. 廖峻鋒 Aug 22,2003 NCCU Computer Center. 學習目標. 建構 Framework 的二大原則 ( 及其標記 ) Unification / Separation Template-Hook 觀念 ( 及其標記 ) Gof Patterns 的五大建構原則 (Meta Patterns) ( 及其標記 )

mignon
Download Presentation

廖峻鋒 Aug 22,2003 NCCU Computer Center

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UML-F tags for Framework Construction Principles and Patterns- The UML Profile for Framework Architectures讀書會第四章 廖峻鋒 Aug 22,2003 NCCU Computer Center

  2. 學習目標 • 建構Framework的二大原則(及其標記) • Unification / Separation • Template-Hook觀念(及其標記) • Gof Patterns的五大建構原則(Meta Patterns)(及其標記) • 所有的Gof皆可歸為這五類。 • 如何自訂標記

  3. Agenda • 背景知識 • Template / Hook • Essential Framework Construction Principles • UML-F for Gof Patterns • UML-F for Domain-specific Patterns • 進階閱讀參考

  4. 背景知識 • 控制權互換(Inversion of Control) • Template / Hook • 三個重要的基本Patterns

  5. [重要]實作和流程控制角色的互換(Inversion of Control) • 傳統的公用函式庫(Library) • 函式由函式庫定義。 • 我們寫主程式,在主程式中呼叫函式。 • 你控制流程,Library提供實作。 • 框架(Framework) • 主程式由框架定義。 • 我們實作函式,被框架定義的主程式所呼叫。 • Framework控制流程,你提供實作!

  6. Inversion of Control

  7. Library Reuse String countStr = “256”; int count = Integer.parseInt(countStr); 你控制流程,Library提供實作! Structured Style!

  8. Framework Reuse public class MyServlet extends HttpServlet { public void doGet(…){ // 提供實作 } } Framework控制流程,你提供實作! Call Back Style!

  9. Meta Patterns • Gof Patterns其實用來用去也都是那幾招。 • 由Template / Hook組合成不同Meta Patterns. • 作者認為各式各樣的Design Patterns只是T / H的不同組合而已。

  10. Template Method /Hook Method • 我們寫Framework時主要邏輯通常會寫在Template Method 中。 • Template Method會呼叫若干Hook Method,Hook Method通常就是「變異點」。 • 只要改寫Hook Method,就可改變Template Method的行為。(課本第68頁中) • 參考下頁的例子。

  11. 範例:Template / Hook Method

  12. Template/Hook Class • Template Class /Hook Class • 擁有Template method的類別稱為Template Class。 • 擁有Hook method的類別稱為Hook Class。 • 同一類別可能同時是Template及Hook Class。(例如:Unif. 、Chain of Resp.)

  13. UML-F層級關係

  14. UML-F (Template / Hook)

  15. 範例 類似name space觀念 可以想成:在做s1這件任務時,B是擔任hook class的角色,做s2時,B是擔任template class的角色…

  16. Hook Scale up • Template Class 可能也是別人的Hook Class • 可參閱上一張投影片

  17. 三個重要的基本Patterns • Delegate[Grand98] - 繼承的替代方案 • Template Method[Gof95]- Inversion of Control的標準方式! • Interface[Grand98] - 利用界面區隔類別使用者(Client)與類別實作(Concrete Classes).

  18. Delegate • Java API中到處都是Delegate. - Patterns in Java ,volume I by Mark Grand.

  19. Delegate範例 觀察:Design Pattern時常混合出現(A.Shalloway et al. 2000)

  20. Interface[Grand98] • Interface規定了一組方法(method),所有實作它的元件都要實作所有方法。 • Client呼叫的是Interface中的方法,所以元件的抽換對Client來說是感覺不到的(不用改code)。

  21. 實作界面就可保証符合規格

  22. ps.其實這是一個strategy pattern java.io.FilenameFilter

  23. Template Method[Gof95] • 一個Browser向HttpServlet發出post時,會觸發doPost()方法。 • 一個Browser向Servlet發出get時,會觸發doGet()方法。 • 判別是get 或 post,由HttpServlet決定,至於doPost(),doGet()由子類別決定。 • Template Method是Framework中最常見到的Design Pattern!

  24. Servlet

  25. Patterns的五大建構原則 • 根據本書的歸納,所有Gof Patterns可分為五大Meta Patterns. • Unification、Separation、Composite、Decorator及Chain-Of-Responsibility(參見p96,Fig 4.24)。

  26. Patterns的五大建構原則

  27. 五大原則(圖) Unification Separation 觀察:Template在子類別!

  28. 建構框架二大基本原則-Essential Framework construction principles • Unification construction principle • Separation construction principle

  29. Unification template、hook在同一個Class Template method Hook method

  30. 範例:登入機制的抽象化

  31. UML-F (Unification) UML-F tags for Unification Construction Principle

  32. Observer Pattern Separation Hook method Template method Template Class 與 Hook Class有委任關係

  33. Interface 範例:Strategy Delegate 觀察:Design Pattern時常混合出現(A.Shalloway et al. 2000)

  34. UML-F(Separation)

  35. 範例:FilenameFilter

  36. Abstract Coupling(課本4.3.1) • Separation 原則時常是Abstract Coupling,所以有時候我們也稱Separation為Abstract Coupling。

  37. Abstract Coupling(課本4.3.1) Abstract coupling 這是一個Factory Method Pattern

  38. UML-F tags for Gof Patterns • Factory Method • Strategy • Composite 這裏僅以Facotry Method為例,說明其方法。其它樣式請自行參考課本附錄B!

  39. Factory Method的成員

  40. UML-F for Factory Method • 類別: • FacM-Creator • FacM-Product • FacM-ConcreteCreator • FacM-ConcreteProduct • 方法 • FacM-facM,FacM-facM,FacM-anOp. 抽象方法!

  41. 範例 : java.net.ContentHandler

  42. UML-F tags for Domain-specific Patterns • Calculation Pattern • 其實這個Pattern就是一個標準的Strategy Pattern. • 將Strategy的UML-F標籤換成自訂的Domain-Specific tag.(參考課本p.108)

  43. Framework進階閱讀 • Building Application Framework (Wiley)-這本很像論文集,不好唸且錯誤很多,宜以讀書會方式加以了解。 • Java Application Framework (Wiley). • 應用架構入門與實例 –台灣本土唯一一本Framework 著作,但是是數年前的著作,前幾章仍有閱讀的價值。(可自MISOO上自由下傳)。

  44. Design Patterns學習地圖 • 精通任一種OO語言及OO基本觀念(繼承封裝多形)。 • Thinking in Java(有中譯本) . • Design Patterns入門 • Applying UML and Patterns: An Introduction to Object-Oriented Analysis, 2/e(有中譯本) • Design Patterns Explained: A New Perspective on Object-Oriented Design(有中譯本) • Design Patterns 於 Java 語言上的實習應用(有中譯本)

  45. Design Patterns學習地圖2 • 觀察別人如何使用Patterns(Java) • Java Design Patterns: A Tutorial • Applied Java Patterns(有中譯本) • Patterns in Java VI,V2. • 活用Patterns • Design Patterns Java Workbook(有中譯本) • Pattern Hatching: Design Patterns Applied(這本是以C++為例).

  46. Design Patterns學習地圖3 • 經典 • Gof(有中譯本) • Architectural Patterns • Patterns of Enterprise Application Architecture • Pattern Oriented Software Architecture (POSA) • 這本書scope非常廣,包含了Software Architecture、Architectural Patterns 、Design Patterns及Idioms。

  47. Design Patterns學習地圖4 • HillSide Group(http://hillside.net) - 由Kent Beck 及Grady Booch建立,是Pattern族群的聖殿。

More Related