1. 1 2014 HTC PROPRIETARY AND CONFIDENTIAL
2016
Design Pattern
Eric Lu
2. 2 2014 HTC PROPRIETARY AND CONFIDENTIAL
Agenda
? Propose of this ppt
? What is Design Pattern
? UML
– Class Diagram
? Classify Design Patterns
– Creational
– Structural
– Behavioral
? Suggestions
3. 3 2014 HTC PROPRIETARY AND CONFIDENTIAL
Propose of this ppt
? You will learn…
– What is Design Pattern
– What is Class Diagram
– Big picture of Design Patterns
? And
– Makes you interesting in Design Patterns!
4. 4 2014 HTC PROPRIETARY AND CONFIDENTIAL
Design Pattern is …
? Why
– 重用公認優良設計,避免解決問題時重蹈覆轍
– 建立通用術語,分析設計時能有對問題的共識
– 幫我們分析,了解問題,避免過早處理細節
? What
– 在一個特定情境(context)中,針對重複出現問題所提出有效地解決方法
? When
– 套用時機
? 設計階段
– 了解客戶需求,完成分析工作(建立use case mode與domain model)後建立design model 時
? 實作階段
– 當設計階段套用design pattern的「作用力(force)」還不是很具體,只能先利用基本的物件導向
設計方法來設計物件與分配責任
– 在實作幾個功能(use case或user story)之後才慢慢發現可以藉由重構(refactoring)方法來套用
design pattern
? 設計時套用可能因為問題尚不清楚而過度設計,實作時重構比較保險 - Erich Gamma
– 選擇套用Scrum,一部分一部分重構
12. 12 2014 HTC PROPRIETARY AND CONFIDENTIAL
Sample Factory Method
? How to Use
– Example in Android / JAVA
? 圖形介面框架中Button,有子類AppCompatButton,CompoundButton,如何實現由子類決定
– Consequence
13. 13 2014 HTC PROPRIETARY AND CONFIDENTIAL
Factory Method
? How to Use
– Consequence
14. 14 2014 HTC PROPRIETARY AND CONFIDENTIAL
Structural
結構關係
16. 16 2014 HTC PROPRIETARY AND CONFIDENTIAL
Adapter
? How to Use
– Example in Android / JAVA
? Iterator 中hasNext() next() remove() 操作不同collection
– Consequence