Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
6.2. 
Move Creation Knowledge to Factory 
6. Creation (6.2) 
YAO, LI-WEI 
2014/12/04 
Qlync Inc., RD Reading 
1
⽤用以具現(Instantiate) 
class的各種資料和程式碼 
蔓延(sprawl)於許多classes 
將創建知識(Creation Knowledges)搬 
移至單個Factory class中 
2
Creation Sprawl 
(Solution Sprawl) 
3
What is Factory? 
Simple Factory 
Factory Method 
Abstract Factory 
http://corey.quickshiftconsulting.com/blog/first-post ...
Simple Factory 
Creation logic in factory, hard to add new product 
5
Factory Method 
Interfaced factory method, OCP (Open Closed Principle), client decide product 
6
Abstract Factory 
Create a family of related objects, use factory method 
7
⽤用以具現(Instantiate) 
class的各種資料和程式 
碼蔓延於許多classes 
將創建知識(Creation Knowledges)搬 
移至單個Factory class中 
8
Pros ana Cons 
(+) 可以統合創建邏輯(creation logic)和具現/組 
態偏好(instantiation/configuration preferences)。︒ 
(+) 將客⼾戶端和創建邏輯(creation ...
Mechanics 
1. 令instantiator經由Creation Method具現product 
2. 建⽴立即將成為Factory的新class 
3. 將Creation Method移至Factory, 設為nonstatic...
Example… 
and 
Discussion… 
http://www.informit.com/articles/article.aspx?p=1398606&seqNum=2 
11
Upcoming SlideShare
Loading in …5
×

6.2 Move Creation Knowledge to Factory - Refactoring to Patterns

637 views

Published on

[Refactoring to Patterns]
6.2 Move Creation Knowledge to Factory

Published in: Software
  • Be the first to like this

6.2 Move Creation Knowledge to Factory - Refactoring to Patterns

  1. 1. 6.2. Move Creation Knowledge to Factory 6. Creation (6.2) YAO, LI-WEI 2014/12/04 Qlync Inc., RD Reading 1
  2. 2. ⽤用以具現(Instantiate) class的各種資料和程式碼 蔓延(sprawl)於許多classes 將創建知識(Creation Knowledges)搬 移至單個Factory class中 2
  3. 3. Creation Sprawl (Solution Sprawl) 3
  4. 4. What is Factory? Simple Factory Factory Method Abstract Factory http://corey.quickshiftconsulting.com/blog/first-post http://blog.csdn.net/dragonwuboy/article/details/16839509 4
  5. 5. Simple Factory Creation logic in factory, hard to add new product 5
  6. 6. Factory Method Interfaced factory method, OCP (Open Closed Principle), client decide product 6
  7. 7. Abstract Factory Create a family of related objects, use factory method 7
  8. 8. ⽤用以具現(Instantiate) class的各種資料和程式 碼蔓延於許多classes 將創建知識(Creation Knowledges)搬 移至單個Factory class中 8
  9. 9. Pros ana Cons (+) 可以統合創建邏輯(creation logic)和具現/組 態偏好(instantiation/configuration preferences)。︒ (+) 將客⼾戶端和創建邏輯(creation logic)解除耦合 (decouple)。︒ (-) 此法比直接具現(direct instantiation; 亦即直接 創建)更令設計複雜⼀一些。︒ 9
  10. 10. Mechanics 1. 令instantiator經由Creation Method具現product 2. 建⽴立即將成為Factory的新class 3. 將Creation Method移至Factory, 設為nonstatic 4. 令instantiator改⽽而具現Factory, 呼叫Factory取得class實體 5. 將具現任務中所需的資料及函式盡可能移至Factory 10
  11. 11. Example… and Discussion… http://www.informit.com/articles/article.aspx?p=1398606&seqNum=2 11

×