1面向对象分析与设计 UML 交互图叶文来 UML 交互图?描述对象间通过消息的交互?用于动态对象建模?有两种类型: –顺序图( sequence diagram) –通信图(communication diagram) –交互纵览图 23何时需要绘制交互图?交互图–是验证逻辑使逻辑清晰的好办法–发现瓶颈的一种很好的机制–用于动态对象建模。类图是静态视图,交互图是动态视图–在用例和类模型之间搭起一座桥梁?描述对象之间以及对象与参与者之间的消息发送关系?发现类并依据其职责构建类的属性和方法–考虑 OO 设计细节时,要落实发送哪些消息、发送给谁、以何种顺序发送为用例绘制交互图时有问题,很可能是你编写的用例不正确! 顺序图?显示用例的行为序列?显示了用例流程中不同对象之间的调用关系?对象、类和参与者都在顺序图中进行描述 4 : A myB : B doTwo doOne doThree public class A { private B myB=new B(); public void doOne() { (); (); } //……} 通信图?以网格方式描述对象交互。 5 : A myB : B 1 : doTwo 2 : doThree doOne6顺序图和通信图?同质的模型,在 CASE 工具中可相互转换?顺序图表示调用流的顺序,由上至下,直观?通信图节省表示空间: Register : Sale makePayment ( cashTendered ) makePayment ( cashTendered ) : Payment create ( cashTendered ) 1 : makePayment ( cashTendered ) : create ( cashTendered ) : Register : Sale : Payment makePayment ( cashTendered ) direction of message 交互图表示法?使用生命线框图表示参与者 7 sales : ArrayList < Sale > : Sales 1 : Sale lifeline box representing an instance of an ArrayList class , parameterized ( templatized ) to hold Sale objects lifeline box representing an unnamed instance of class Sale lifeline box representing a named instance sales [ i ] : Sale lifeline box representing one instance of class Sale , selected from the sales ArrayList < Sale > collection x : List ?metaclass? Font lifeline box representing the class Font , or more precisely , that Font is an instance of class Class – an instance of a metaclass related example List is an interface in UML 1. x we could not use an interface here , but in UML 2 , this ( or an abstract class ) is legal8 ?消息格式–方括号所括的是可选部分– message-name: 消息名– argument-list: 消息的参数列表–示例 P165 [return-value:=]message-name ([argument-list]) :returnType ?单实例类对象–对象实例化时,只能存在一个实例–在生命线框图右上角标识“1”9顺序图基本表示法?生命线框、消息、控制期和执行活动条 10 : Register : Sale doA doB doXdoC doD typical sychronous message shown with a filled - arrow line a found message whose sender will not be specified execution specificat
10uml交互图 来自淘豆网m.daumloan.com转载请标明出处.