设计模式案例(十二)

上传人:小**** 文档编号:240707406 上传时间:2024-05-01 格式:PPT 页数:47 大小:881.50KB
返回 下载 相关 举报
设计模式案例(十二)_第1页
第1页 / 共47页
设计模式案例(十二)_第2页
第2页 / 共47页
设计模式案例(十二)_第3页
第3页 / 共47页
点击查看更多>>
资源描述
UML-F tags for Framework Construction Principles and Patterns-The UML Profile for Framework Architectures讀書會第四章廖峻鋒Aug 22,2003NCCU Computer Center國立政治大學電子計算機中心學習目標n建構Framework的二大原則(及其標記)nUnification/SeparationnTemplate-Hook觀念(及其標記)nGof Patterns的五大建構原則(Meta Patterns)(及其標記)n所有的Gof皆可歸為這五類。n如何自訂標記國立政治大學電子計算機中心Agendan背景知識nTemplate/HooknEssential Framework Construction PrinciplesnUML-F for Gof PatternsnUML-F for Domain-specific Patternsn進階閱讀參考國立政治大學電子計算機中心背景知識n控制權互換(Inversion of Control)nTemplate/Hookn三個重要的基本Patterns國立政治大學電子計算機中心重要實作和流程控制角色的互換(Inversion of Control)n傳統的公用函式庫(Library)n函式由函式庫定義。n我們寫主程式,在主程式中呼叫函式。n你控制流程,Library提供實作。n框架(Framework)n主程式由框架定義。n我們實作函式,被框架定義的主程式所呼叫。nFramework控制流程,你提供實作!國立政治大學電子計算機中心Inversion of Control國立政治大學電子計算機中心Library ReuseString countStr=“256”;int count=Integer.parseInt(countStr);你控制流程,你控制流程,Library提供實作提供實作!Structured Style!國立政治大學電子計算機中心Framework Reusepublic class MyServlet extends HttpServlet public void doGet()/提供實作 Framework控制流程,你提供實作控制流程,你提供實作!Call Back Style!國立政治大學電子計算機中心Meta Patterns nGof Patterns其實用來用去也都是那幾招。n由Template/Hook組合成不同Meta Patterns.n作者認為各式各樣的Design Patterns只是T/H的不同組合而已。國立政治大學電子計算機中心Template Method/Hook Methodn我們寫Framework時主要邏輯通常會寫在Template Method 中。nTemplate Method會呼叫若干Hook Method,Hook Method通常就是變異點。n只要改寫Hook Method,就可改變Template Method的行為。(課本第68頁中)n參考下頁的例子。國立政治大學電子計算機中心範例:Template/Hook Method國立政治大學電子計算機中心Template/Hook ClassnTemplate Class/Hook Classn擁有Template method的類別稱為Template Class。n擁有Hook method的類別稱為Hook Class。n同一類別可能同時是Template及Hook Class。(例如:Unif.、Chain of Resp.)國立政治大學電子計算機中心UML-F層級關係國立政治大學電子計算機中心UML-F(Template/Hook)國立政治大學電子計算機中心範例類似name space觀念可以想成:在做s1這件任務時,B是擔任hook class的角色,做s2時,B是擔任template class的角色國立政治大學電子計算機中心Hook Scale upnTemplate Class 可能也是別人的Hook Classn可參閱上一張投影片國立政治大學電子計算機中心三個重要的基本PatternsnDelegateGrand98-繼承的替代方案nTemplate MethodGof95-Inversion of Control的標準方式!nInterfaceGrand98-利用界面區隔類別使用者(Client)與類別實作(Concrete Classes).國立政治大學電子計算機中心DelegatenJava API中到處都是Delegate.-Patterns in Java,volume I by Mark Grand.國立政治大學電子計算機中心Delegate範例觀察:Design Pattern時常混合出現(A.Shalloway et al.2000)國立政治大學電子計算機中心InterfaceGrand98 nInterface規定了一組方法(method),所有實作它的元件都要實作所有方法。nClient呼叫的是Interface中的方法,所以元件的抽換對Client來說是感覺不到的(不用改code)。國立政治大學電子計算機中心實作界面就可保証符合規格國立政治大學電子計算機中心java.io.FilenameFilterps.其實這是一個strategy pattern國立政治大學電子計算機中心Template MethodGof95n一個Browser向HttpServlet發出post時,會觸發doPost()方法。n一個Browser向Servlet發出get時,會觸發doGet()方法。n判別是get 或 post,由HttpServlet決定,至於doPost(),doGet()由子類別決定。nTemplate Method是Framework中最常見到的Design Pattern!國立政治大學電子計算機中心Servlet國立政治大學電子計算機中心Patterns的五大建構原則n根據本書的歸納,所有Gof Patterns可分為五大Meta Patterns.nUnification、Separation、Composite、Decorator及Chain-Of-Responsibility(參見p96,Fig 4.24)。國立政治大學電子計算機中心Patterns的五大建構原則國立政治大學電子計算機中心五大原則(圖)UnificationSeparation觀察:Template在子類別!國立政治大學電子計算機中心建構框架二大基本原則-Essential Framework construction principles Unification construction principle Separation construction principle國立政治大學電子計算機中心UnificationTemplate methodHook methodtemplate、hook在同一個Class國立政治大學電子計算機中心範例:登入機制的抽象化國立政治大學電子計算機中心UML-F(Unification)UML-F tags for Unification Construction Principle國立政治大學電子計算機中心SeparationTemplate methodHook methodTemplate Class 與 Hook Class有委任關係Observer Pattern國立政治大學電子計算機中心範例:StrategyDelegate觀察:Design Pattern時常混合出現(A.Shalloway et al.2000)Interface國立政治大學電子計算機中心UML-F(Separation)國立政治大學電子計算機中心範例:FilenameFilter國立政治大學電子計算機中心Abstract Coupling(課本4.3.1)nSeparation 原則時常是Abstract Coupling,所以有時候我們也稱Separation為Abstract Coupling。國立政治大學電子計算機中心Abstract Coupling(課本4.3.1)Abstract coupling這是一個Factory Method Pattern國立政治大學電子計算機中心UML-F tags for Gof PatternsnFactory MethodnStrategynComposite這裏僅以Facotry Method為例,說明其方法。其它樣式請自行參考課本附錄B!國立政治大學電子計算機中心Factory Method的成員國立政治大學電子計算機中心UML-F for Factory Methodn類別:nFacM-Creator nFacM-ProductnFacM-ConcreteCreatornFacM-ConcreteProductn方法nFacM-facM,FacM-facM,FacM-anOp.抽象方法!國立政治大學電子計算機中心範例:.ContentHandler國立政治大學電子計算機中心UML-F tags for Domain-specific PatternsnCalculation Patternn其實這個Pattern就是一個標準的Strategy Pattern.n將Strategy的UML-F標籤換成自訂的Domain-Specific tag.(參考課本p.108)國立政治大學電子計算機中心Framework進階閱讀nBuilding Application Framework(Wiley)-這本很像論文集,不好唸且錯誤很多,宜以讀書會方式加以了解。nJava Application Framework(Wiley).n應用架構入門與實例 台灣本土唯一一本Framework 著作,但是是數年前的著作,前幾章仍有閱讀的價值。(可自MISOO上自由下傳)。國立政治大學電子計算機中心Design Patterns學習地圖n精通任一種OO語言及OO基本觀念(繼承封裝多形)。nThinking in Java(有中譯本).nDesign Patterns入門nApplying UML and Patterns:An Introduction to Object-Oriented Analysis,2/e(有中譯本)nDesign Patterns Explained:A New Perspective on Object-Oriented Design(有中譯本)nDesign Patterns 於 Java 語言上的實習應用(有中譯本)國立政治大學電子計算機中心Design Patterns學習地圖2n觀察別人如何使用Patterns(Java)nJava Design Patterns:A TutorialnApplied Java Patterns(有中譯本)nPatterns in Java VI,V2.n活用PatternsnDesign Patterns Java Workbook(有中譯本)nPattern Hatching:Design Patterns Applied(這本是以C+為例).國立政治大學電子計算機中心Design Patterns學習地圖3n經典nGof(有中譯本)nArchitectural PatternsnPatterns of Enterprise Application ArchitecturenPattern Oriented Software Architecture(POSA)這本書scope非常廣,包含了Software Architecture、Architectural Patterns、Design Patterns及Idioms。國立政治大學電子計算機中心Design Patterns學習地圖4nHillSide Group(http:/)-由Kent Beck 及Grady Booch建立,是Pattern族群的聖殿。
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 商业管理 > 营销创新


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!