Chapter 15 UML交互图·。 ●●●●● ●●●● ●●。●●
Chapter 15 UML交互图
●●●●● ●●●● 目标 ●●● ●●●● ●●0● 学习UML交互图(顺序图和通信图)
目标 ⚫ 学习UML交互图(顺序图和通信图)
●●● ●●●●● ●●●● 简介 ●●● ●●●● ●●0● UML使用交互图( interaction diagram)来描述 对象间消息的交互,用于动态对象建模。 ●交互图有两种类型: ●顺序图( sequence diagram) 通信图( communication diagram)
简介 ⚫ UML使用交互图(interaction diagram)来描述 对象间消息的交互,用于动态对象建模。 ⚫ 交互图有两种类型: ⚫ 顺序图(sequence diagram) ⚫ 通信图(communication diagram)
●●● ●●●●● ●●●● 顺序图的示例 ●●● ●●●● ●●0● public class At A my B: B private B my B= new BO public void dooner doone my B do Two: do two my B. doThreeo do three
顺序图的示例 : A myB : B doTwo doOne doThree public class A{ private B myB = new B(); public void doOne(){ myB.doTwo(); myB.doThree(); } }
●●● ●●●●● ●●● 通信图的示例 ●●● ●●●● ●●0● public class At door private B my B= new BO public void dooner 1: doTwo my B do Two: 2 dothree my B. doThreeo my B
通信图的示例 public class A{ private B myB = new B(); public void doOne(){ myB.doTwo(); myB.doThree(); } } : A myB : B 1: doTwo 2: doThree doOne
●●● ●●● ●●●●● ●●●● 顺序图和通讯图的优点和缺点 ●●● ●●●● ●●0● ●顺序图 ●优点:能够清楚地表示详细的顺序和时间排序,有 丰富的表示法 缺点:强制在右侧增加对象,消耗水平空间 通信图 ●优点:有效利用空间 ●缺点:不易查阅消息的顺序,表示法不够丰富
顺序图和通讯图的优点和缺点 ⚫ 顺序图 ⚫ 优点:能够清楚地表示详细的顺序和时间排序,有 丰富的表示法 ⚫ 缺点:强制在右侧增加对象,消耗水平空间 ⚫ 通信图 ⚫ 优点:有效利用空间 ⚫ 缺点:不易查阅消息的顺序,表示法不够丰富
●●● ●●●●● ●●● 交互图表示法的公共元素 ●●● ●●●● ●●0● 对象及单实例对象 消
交互图表示法的公共元素 ⚫ 对象及单实例对象 ⚫ 消息
●●●●● ● ●●● 使用生命线框图表示参与者 ●●● ●●●● ●●0● lifeline box representing an lifeline box representing a Font, or more precisely, that Font is unnamed instance of class sale named instance instance of class class-an instance of a metaclass aclass》 Sale s1: Sale List is an interface lifeline box representing an feline box representing instance of an Array List class, one instance of class sale in UML 1.x we could not use an parameterized templatized)to selected from the sales terface here, but in UML 2, this(or hold Sale objects Array List collection an abstract class)is legal x: List Array List sales[i]: Sale example
使用生命线框图表示参与者 sales: ArrayList :Sale s1 : 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 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 legal
●●●●● ●●●● ●●● 单实例类对象 ●●●● ●●0● Register Store the‘1 implies this is a Singleton and accessed doX via the singleton pattern
单实例类对象 : Register 1 : Store doA doX the ‘1’ implies this is a Singleton, and accessed via the Singleton pattern
●●● ●●●●● ●●●● 消息表达式 ●●● ●●●● ●●0● ●交互图展示了对象之间的消息;UML对于这些 消息表达式具有标准语法: return message(parameter: parameter Type, .. return T ype initialize(code) initialize d= getProductDesc(id d= getProductDesc(id: ItemID) d= getProductDesc(id: ItemID): ProductDescription
消息表达式 ⚫ 交互图展示了对象之间的消息;UML对于这些 消息表达式具有标准语法: return = message(parameter : parameterType,….):returnType ⚫ 例 initialize(code) initialize d = getProductDesc(id) d = getProductDesc(id : ItemID) d = getProductDesc(id : ItemID) : ProductDescription