- 2
- 0
- 约4.35千字
- 约 45页
- 2017-05-06 发布于四川
- 举报
国立政治university电子计算机中心
2001/11/1 Understanding Design Patterns- for DIDC 廖峻鋒 Apr 28,2004 NCCU Computer Center Agenda Software Patterns觀念複習 LSP、OCP and DI Template Method、Factory、Singleton DesignPatterns的分類 Recommended Readings Q A Patterns 與棋譜 Why Patterns ? 增廣見聞、增加經驗。 開發人員共同的術語。 簡化軟體設計文件中的描述。 The Pattern System 由[POSA96]首先提出對Patterns的分類 將Pattern從「鉅觀」到「微觀」加以分類 Architectural Patterns (例如:MVC、Layer) Design Patterns (例如:Gof的23個patterns) Idioms (例如大量接合字串問題或Code Style) 一些重要的OO技術 LSP:Liskov代換法則 OCP:Open – Close Principle Dependency Injection:元件注入技術 LSP:Liskov代換法則 所有的子類別皆可代父出征 實作界面就可保証符合規格 Interface Interface規定了一組契約(method),所有實作它的類別都要實作所有方法。 Client呼叫的是Interface中的方法,所以元件的抽換對Client來說是感覺不到的(不用改code)。 OCP Open for extension;close for modification Refer to “The Open – Close Princlple Tutorial”. 元件注入Dependency Injection Dependency Injection provide help us to implement the IoC Interface Injection (type 1 IoC) Setter Injection (type 2 IoC) Constructor Injection (type 3 IoC) Before Adapting DI After Adapting DI LoginModule Before Adapting DI After Adapting DI DI Frameworks Apache Avalon Framework (type 1 IoC) Spring Framework (type 2 IoC) Pico Container (type 3 IoC) Template Method /Hook Method Framework的作者通常將主要邏輯寫在Template Method 中。 Template Method會呼叫若干Hook Method,Hook Method通常就是「變異點(Hot Spot)」。 覆寫Hook Method,就可改變Template Method的行為。( 例如Servlet的doGet()/doPost() ) Servlet Factory 一般create一個類別的instance時,我們會使用new 如果在runtime才能決定要new那個類別怎麼辦? 範例:時常需要切換多台資料庫 範例:時常需要切換多台資料庫 Factory的型式 simple static factory Factory method (Gof) Abstract factory (Gof) Simple Static Factory CarFactory的實作 public class CarFactory { public static createCar(String carType){ if (carType==…) else if(…) else … } } Refactoring by Factory Method Pattern Using Map as Factory Container CarFactory carFactory = getCarFactory(“BMW”); BmwCar bmwCar = (BmwCar) carFactory.create(); getCarFactory without mutiple if…else CarFactory getCarFactory(String carType) { return carFactoryContainer.get(carType); } Si
您可能关注的文档
- 可编程中断操纵器Intel8259A.ppt
- 台湾加高电子职工礼仪讲训教材.ppt
- 台湾university历史学系教授.ppt
- 台湾学生占据立法院.ppt
- 台湾蝴蝶甲天下演示课件.ppt
- 台阶写作手法赏析作者谈.pptx
- 台湾奥美的管理品牌之道.ppt
- 台阶200409051136.ppt
- 史明媚老师新讲义.ppt
- 台湾环岛风情8日.ppt
- 河北盐山中学等校2025-2026学年上学期高三一模化学试卷(含解析).docx
- 河北正定中学2025-2026学年高一上学期期末考试物理试卷(含解析).docx
- 河北张家口市怀安县2025-2026学年第一学期期末教学综合评价八年级地理试卷(含解析).docx
- 河南安阳市殷都区2025-2026学年第一学期期末教学质量检测七年级地理试卷(含解析).docx
- 河南安阳市滑县2025一2026学年第一学期期末学业质量监测八年级地理试题(含解析).docx
- 河南安阳市林州市2025-2026学年上学期期末考试高一政治试题(含解析).docx
- 河南焦作市武陟县第一中学2025-2026学年高一上学期1月月考语文试卷(含解析).docx
- 河南济源市2025-2026学年上学期期末学业质量调研七年级历史试卷(含解析).docx
- PICC导管并发症的紧急处理与护理.pptx
- 河南鹤壁市2025-2026学年高二上学期期末考试生物试题(含解析).docx
原创力文档

文档评论(0)