Creator

Problem:

  Who should be responsible for creating a new instance of some class?

 

其實這和上次提到的information expert 有點類似,都是在探討責任歸屬

只是說Creator 要更細的去討論說,誰應該負責去把某個class 的 instance 建出來

那Larman有提出下面的解法

 

Solution:

 Assign class B the responsibility to create an instance of class A if one of these is true:

● B "contains" or compositely aggregates A.

● B records A

● B closely uses A

● B has the initializing data for A that will be passed to A when it is created. Thus B is an Expert with 

    respect to creating A .

creator.PNG

 

參考:

[1] Applying UML and Patterns,Third Edition,Craig Larman


 

GRASP Pattern- Information Expert

 

arrow
arrow
    文章標籤
    GRASP Pattern OOAD Creator
    全站熱搜
    創作者介紹
    創作者 Mark Zhang 的頭像
    Mark Zhang

    讀處

    Mark Zhang 發表在 痞客邦 留言(0) 人氣()