UML序列图总结

jopen 12年前
     <p><strong>        序列图主要用于展示对象之间交互的顺序。</strong></p>    <p>        序列图将交互关系表示为一个二维图。纵向是时间轴,时间沿竖线向下延伸。横向轴代表了在协作中各独立对象的类元角色。类元角色用生命线表示。当对象存在时,角色用一条虚线表示,当对象的过程处于激活状态时,生命线是一个双道线。</p>    <p>        消息用从一个对象的生命线到另一个对象生命线的箭头表示。箭头以时间顺序在图中从上到下排列。 </p>    <p>        序列图中涉及的元素:</p>    <p><strong>        1. </strong><strong>生命线:</strong><br /> </p>    <p>        生命线名称可带下划线。当使用下划线时,意味着序列图中的生命线代表一个类的特定实例。</p>    <p style="text-align:center;"><img alt="UML序列图总结" src="https://simg.open-open.com/show/d47cd6056ec3a63ed0f0903a0e2eb98d.png" width="552" height="275" /> </p>    <p><strong>        2. </strong><strong>同步消息</strong></p>    <p>        发送人在它继续之前,将等待同步消息响应。</p>    <p style="text-align:center;"><img alt="UML序列图总结" src="https://simg.open-open.com/show/8e96c1aaa07823cb9c70dc6fd8b310c9.png" width="361" height="190" />         </p>    <p><strong>        3. </strong><strong>异步消息</strong></p>    <p>        在发送方继续之前,无需等待响应的消息。</p>    <p style="text-align:center;"><img alt="UML序列图总结" src="https://simg.open-open.com/show/e7dd1348b9873ca38013b581e6606847.png" width="341" height="256" /> </p>    <p><strong>        4. </strong><strong>注释</strong></p>    <p style="text-align:center;"><strong><img alt="UML序列图总结" src="https://simg.open-open.com/show/f3364acd4c6f7e65b0c46791bbad1d69.png" width="330" height="273" /><br /> </strong></p>    <p>        <strong>5. </strong><strong>约束</strong></p>    <p>        约束的符号很简单;格式是: [Boolean Test]</p>    <p style="text-align:center;"><img alt="UML序列图总结" src="https://simg.open-open.com/show/0a3b9a94f8142bed5d19bb1183086f85.png" width="350" height="190" /> </p>    <p>        <strong>6. </strong><strong>组合片段</strong></p>    <p><strong>        </strong><strong>组合片段</strong><strong>用来解决交互执行的条件及方式</strong>。它允许在序列图中直接表示逻辑组件,用于通过指定条件或子进程的应用区域,为任何生命线的任何部分定义特殊条件和子进程。</p>    <p>        常用的组合片段有:</p>    <p><strong>        抉择(Alt</strong><strong>)</strong></p>    <p>        抉择用来指明在两个或更多的消息序列之间的互斥的选择,相当于经典的if..else..。</p>    <p>        抉择在任何场合下只发生一个序列。 可以在每个片段中设置一个临界来指示该片段可以运行的条件。<strong>else</strong> 的临界指示其他任何临界都不为 True 时应运行的片段。如果所有临界都为 False 并且没有 <strong>else</strong>,则不执行任何片段。</p>    <p style="text-align:center;"><img alt="UML序列图总结" src="https://simg.open-open.com/show/d5bc8e517728901fc5fe1354e54c2a67.png" width="558" height="402" /> </p>    <p><strong>        选项(Opt</strong><strong>)</strong></p>    <p>        包含一个可能发生或不发生的序列</p>    <p style="text-align:center;"><img alt="UML序列图总结" src="https://simg.open-open.com/show/9eb7719247a0e2c1b0b6e1359c037d3d.png" width="558" height="312" /> </p>    <p><strong>        循环(Loop</strong><strong>)</strong></p>    <p>        片段重复一定次数。 可以在临界中指示片段重复的条件。</p>    <p style="text-align:center;"><strong><img alt="UML序列图总结" src="https://simg.open-open.com/show/a64f5b3c4d53ce03aaabfd8e850ebecf.png" width="369" height="263" /> </strong></p>    <p><strong>        并行(Par</strong><strong>)</strong></p>    <p style="text-align:center;"><img alt="UML序列图总结" src="https://simg.open-open.com/show/03a2ac798b1ab6e353616f4a4d345fd2.png" width="384" height="497" /> </p>    <p><strong>        下表列出了常用的组合片段:</strong></p>    <table border="1" cellspacing="0" cellpadding="0">     <tbody>      <tr>       <td valign="top" width="14%"> <p align="left">片段类型</p> </td>       <td valign="top" width="11%"> <p align="left">名称</p> </td>       <td valign="top" width="74%"> <p align="left">说明</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Opt</strong></p> </td>       <td valign="top" width="11%"> <p align="left">选项</p> </td>       <td valign="top" width="74%"> <p align="left">包含一个可能发生或可能不发生的序列。 可以在临界中指定序列发生的条件。</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Alt</strong></p> </td>       <td valign="top" width="11%"> <p align="left">抉择</p> </td>       <td valign="top" width="74%"> <p align="left">包含一个片段列表,这些片段包含备选消息序列。 在任何场合下只发生一个序列。</p> <p align="left">可以在每个片段中设置一个临界来指示该片段可以运行的条件。 <strong>else</strong> 的临界指示其他任何临界都不为 True 时应运行的片段。 如果所有临界都为 False 并且没有 <strong>else</strong>,则不执行任何片段。</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Loop</strong></p> </td>       <td valign="top" width="11%"> <p align="left">循环</p> </td>       <td valign="top" width="74%"> <p align="left">片段重复一定次数。 可以在临界中指示片段重复的条件。</p> <p align="left">Loop 组合片段具有<strong>“Min”</strong>和<strong>“Max”</strong>属性,它们指示片段可以重复的最小和最大次数。 默认值是无限制。</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Break</strong></p> </td>       <td valign="top" width="11%"> <p align="left">中断</p> </td>       <td valign="top" width="74%"> <p align="left">如果执行此片段,则放弃序列的其余部分。 可以使用临界来指示发生中断的条件。</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Par</strong></p> </td>       <td valign="top" width="11%"> <p align="left">并行</p> </td>       <td valign="top" width="74%"> <p align="left">并行处理。 片段中的事件可以交错。</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Critical</strong></p> </td>       <td valign="top" width="11%"> <p align="left">关键</p> </td>       <td valign="top" width="74%"> <p align="left">用在 Par 或 Seq 片段中。 指示此片段中的消息不得与其他消息交错。</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Seq</strong></p> </td>       <td valign="top" width="11%"> <p align="left">弱顺序</p> </td>       <td valign="top" width="74%"> <p align="left">有两个或更多操作数片段。 涉及同一生命线的消息必须以片段的顺序发生。 如果消息涉及的生命线不同,来自不同片段的消息可能会并行交错。</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Strict</strong></p> </td>       <td valign="top" width="11%"> <p align="left">强顺序</p> </td>       <td valign="top" width="74%"> <p align="left">有两个或更多操作数片段。 这些片段必须按给定顺序发生。</p> </td>      </tr>     </tbody>    </table>    <p><strong>        </strong><strong>有关如何解释序列的片段</strong></p>    <p>        默认情况下,序列图表明可能发生的一系列消息。 在运行的系统中,可能会出现您未选择显示在关系图上的其他消息。</p>    <p>        以下片段类型可用于更改此释义:</p>    <table border="1" cellspacing="0" cellpadding="0">     <tbody>      <tr>       <td valign="top" width="14%"> <p align="left">片段类型</p> </td>       <td valign="top" width="11%"> <p align="left">名称</p> </td>       <td valign="top" width="74%"> <p align="left">说明</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Consider</strong></p> </td>       <td valign="top" width="11%"> <p align="left">考虑</p> </td>       <td valign="top" width="74%"> <p align="left">指定此片段描述的消息列表。 其他消息可发生在运行的系统中,但对此描述来说意义不大。</p> <p align="left">在<strong>“Messages”</strong>属性中键入该列表。</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Ignore</strong></p> </td>       <td valign="top" width="11%"> <p align="left">忽略</p> </td>       <td valign="top" width="74%"> <p align="left">此片段未描述的消息列表。 这些消息可发生在运行的系统中,但对此描述来说意义不大。</p> <p align="left">在<strong>“Messages”</strong>属性中键入该列表。</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Assert</strong></p> </td>       <td valign="top" width="11%"> <p align="left">断言</p> </td>       <td valign="top" width="74%"> <p align="left">操作数片段指定唯一有效的序列。 通常用在 Consider 或 Ignore 片段中。</p> </td>      </tr>      <tr>       <td valign="top" width="14%"> <p align="left"><strong>Neg</strong></p> </td>       <td valign="top" width="11%"> <p align="left">否定</p> </td>       <td valign="top" width="74%"> <p align="left">此片段中显示的序列不得发生。 通常用在 Consider 或 Ignore 片段中。</p> </td>      </tr>     </tbody>    </table>