Visual Paradigm使用技巧:類圖的建模設(shè)計(jì)模式
1. 創(chuàng)建一個(gè)名為Design Patterns的新項(xiàng)目
2. 創(chuàng)建一個(gè)名為Visitor的類圖。

3. 從圖表工具欄中選擇Class,點(diǎn)擊圖表創(chuàng)建一個(gè)類,命名為Client。

4. 將鼠標(biāo)光標(biāo)移到Client類上, 然后拖出Association > Class以創(chuàng)建關(guān)聯(lián)的類Visitor。

5. 右擊Visitor, 選擇Model Element Properties > Abstract設(shè)置為摘要。

6. 右擊Visitor類, 從下拉菜單中選擇Add > Operation。

7. 將操作命名為VisitConcreteElement(ConcreteElement)。
8. 在VisitConcreteElement上用鼠標(biāo)右鍵點(diǎn)擊,然后選擇Model Element Properties > Abstract將其設(shè)置為摘要。

9. 將鼠標(biāo)光標(biāo)移動(dòng)到Visitor類之上,拖放Generalization > Class創(chuàng)建子類ConcreteVisitor。

10. 我們需要讓具體的訪客從visitor類處繼續(xù)操作。右擊ConcreteVisitor然后從下拉菜單處選擇Related Elements > Realize all Interfaces。

11. 將鼠標(biāo)光標(biāo)移動(dòng)到Client類,然后拖拽Association > Class創(chuàng)建相關(guān)的類ObjectStructure。

12. 將鼠標(biāo)光標(biāo)移動(dòng)到ObjectStructure類,然后拖拽Association > Class創(chuàng)建相關(guān)的類Element。

13. 右鍵點(diǎn)擊Element,選擇Model Element Properties > Abstract將其設(shè)置為摘要。
14. 右鍵點(diǎn)擊Element類,從下拉菜單中選擇Add > Operation,將操作命名為Accept(Visitor)。
15. 右鍵點(diǎn)擊Accept(Visitor),選擇Model Element Properties > Abstract將其設(shè)置為摘要。到目前為止,整個(gè)圖表就成為下面這個(gè)樣子:

16. 將鼠標(biāo)光標(biāo)移動(dòng)到Element類上,拖放Generalization > Class創(chuàng)建子類ConcreteElement。

17. 我們需要使具體的元素從元素類繼承操作。右鍵點(diǎn)擊ConcreteElement然后從下拉菜單中選擇Related Elements > Realize all Interfaces。

18. 在實(shí)際工作中,可能有多個(gè)ConcreteVisitor類。基于此種情形,套用ConcreteVisitor作為PTN Cloneable。右鍵點(diǎn)擊ConcreteVisitor類然后從下拉菜單中選擇Stereotypes > Stereotypes...

19. 在Class Specification中的Stereotypes標(biāo)簽,選擇PTN Cloneable,然后點(diǎn)擊>進(jìn)行類的指派,再點(diǎn)擊OK進(jìn)行確認(rèn)。

20. 在ConcreteElement上重復(fù)18,19步驟。

21. 在Visitor, Element和ConcreteElement中可能包含了多個(gè)操作。基于此種情形,將它們套用為PTN Members Creatable。將18和19步驟套用到Visitor, Element和ConcreteElement作為PTN Members Creatable。至此,原型的結(jié)構(gòu)如下所示:
