📄 8sequencediagrams.html
字号:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Together Tutorial -- Part 8</title>
<link href="tutor.css" rel="styleSheet" type="text/css">
</head>
<body bgcolor="white" link="#003399" alink="#999999" vlink="#000066">
<div align="left">
<p class="head2">
<span style="font-size: 9pt">
<a href="mailto:%20e.w@263.net">翻译: 李颖(e.w@263.net)</a></span></p>
</div>
<div align="center">
<p class="head2"><a name="top"></a>Together 教程<br>8: 时序图</p>
</div>
<p>类图给出了模型的整体结构. 但类图是静态图, 与模型的行为无关. 在这一课中, 你将创建一些时序图来描述行为是如何发生的.</p>
<p>Together 能从实际的代码中生成时序图. 它也能从时序图生成代码, 包括:</p>
<ul>
<li>类声明.
<li>操作声明.
<li>方法体. (只在明确需求时才生成.)
</ul>
<p>这一课包括生成代码和时序图. 在结束时我们将讨论如何创建超链接来连接相关的工程实体.</p>
<p><b>目录:</b></p>
<ul>
<li><a class="onPage" href="#tab">创建一个时序图草图</a><li><a class="onPage" href="#correlate">
将一般对象关联到类, 将一般消息关联到操作</a><li><a class="onPage" href="#code">
在模型图中放置控制代码</a><li><a class="onPage" href="#implement">从模型图实现代码</a><li><a class="onPage" href="#final">
从代码生成模型图</a><li><a class="onPage" href="#hyperlink">超链接工程元素</a><li><a class="onPage" href="#tip">
技巧</a></ul>
<p><img height="2" width="900" src="images/generic/rainbow2.gif" alt="Divider line"></p>
<p class="head3"><a name="tab"></a>创建一个时序图草图</p>
<p>首先打开 <b>AirlinePD</b> 模型图. 你的第一个时序图将用来描述问题域中的活动.</p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 在 <b>AirlinePD</b>
包中, 创建一个名为 <b>FindRevenue</b> 的时序图.</td>
</tr>
</table>
</td>
</tr>
</table>
<p>要创建一个新的模型图, 点击 Designer 工具条中最左边的按钮(<img src="images/icons/diagrambutton.gif" width="12" height="14" border="0" hspace="2" align="top" alt="Diagram button">).
下面是我们的新模型图对话框. 我们要填写模型图名称和描述.</p>
<p><img src="images/airline/seqdiagdialog.png" width="596" height="406" border="0" alt="New sequence diagram" hspace="10" vspace="10"></p>
<p>时序图工具条中包含五个按钮用于创建模型图.</p>
<ul>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#CCCCCC">
<table border="0" cellpadding="2" cellspacing="2" width="303">
<tr>
<td bgcolor="white" width="20"><img src="images/icons/actoricon.png" width="12" height="15" border="0" hspace="2"></td>
<td bgcolor="white" width="53">角色</td>
<td bgcolor="white" width="210">可以开始消息链</td>
</tr>
<tr>
<td bgcolor="white" width="20"><img src="images/icons/objecticon.png" width="11" height="16" border="0" hspace="2"></td>
<td bgcolor="white" width="53">对象</td>
<td bgcolor="white" width="210">接受和发送消息</td>
</tr>
<tr>
<td bgcolor="white" width="20"><img src="images/icons/messageicon.png" width="16" height="7" border="0" hspace="2"></td>
<td bgcolor="white" width="53">
</table>
</table>
<li>消息</td>
<td bgcolor="white" width="210">连接对象</td>
</tr>
<tr>
<td bgcolor="white" width="20"><img src="images/icons/selflink.gif" width="15" height="15" border="0" alt="self link" hspace="2"></td>
<td bgcolor="white" width="53">
<li>自消息</td>
<td bgcolor="white" width="210">调用同一个对象中的方法</td>
</tr>
<tr>
<td bgcolor="white" width="20"><img src="images/icons/block.gif" width="13" height="13" border="0" hspace="2" alt="code block"></td>
<td bgcolor="white" width="53">
<li>语句块
<table>
<td bgcolor="white" width="210">控制语句(循环语句等)</td>
<dl></dl>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 在时序图最左侧放置一个角色.
然后放置三个对象.</td>
</tr>
</table>
</td>
</tr>
</table>
<p>Together 在除了角色之外的每个对象下方显示一个点状的生命线, 角色下放显示一个窄的矩形条.</p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 创建一个从角色到 <b>Object2</b>
的消息.</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#CCCCCC" valign="top">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">你可以将消息从一个生命线拖动到另一个.
类似于在类图中拖动一个类关联以及在活动图中拖动一个转换. <p>
完成这个操作后, 目标对象的生命线中将出现一个(矩形)活动条, 活动条开始于箭头处. 活动条可以拉长,
缩短, 也可以在生命线中移动.</p>
<p>当你把光标移动到合法的源生命线和目标生命线时, Together 将在其周围显示一个光圈.</p>
</td>
<td valign="top" bgcolor="white">
<p><img src="images/airline/sddragnewoperation.png" width="223" height="140" border="0" alt="Dragging a message" hspace="5"></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
<tr>
<td bgcolor="#993300">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#ffffcc" width="100%">
<tr>
<td bgcolor="#ffffcc"><b>操作步骤:</b> 创建一个从 <b>Object2</b>
到 <b>Object3</b> 的消息.</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#CCCCCC">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">
确定你创建的这个消息在活动条内部而不是在其下方. 否则将会在 <b>Object2</b>
的生命线中出现一个新的独立的活动条.
<p>右图显示了时序图中严格的一般类和一般消息, 它们与类图中的对象和操作完全没有关系.</p>
</td>
<td valign="top" bgcolor="white">
<p><img src="images/airline/sdvanilla.png" width="421" height="162" border="0" alt="Generic diagram" hspace="5"></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<hr>
<p class="head3"><a name="correlate"></a>将一般对象关联到类, 将一般消息关联到操作</p>
<p>你可以将一般对象转换为一个已存在的或者新建类的实例. 你也可以将一般消息转换为这些类中的实际操作.</p>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="#993300" width="100%">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -