📄 4classes.html
字号:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Together Tutorial -- Part 4</title>
<link href="tutor.css" rel="styleSheet" type="text/css">
</head>
<body bgcolor="white" link="#003399" alink="#999999" vlink="#000066">
<p class="head2" align="left"><span style="font-size: 9pt"><a href="mailto:%20e.w@263.net">翻译: 李颖(e.w@263.net)</a></span></p>
<center>
<p class="head2"><a name="top"></a>Together 教程<br>
4: 模型图与类</p>
</center>
<p>你现在已经创建了一个新的工程,
并将你的工作组织成了包的形式.
而且你通过用例图大致描述了用户需求.
在这一课中,
你将创建类, 在 problem domain
包中填充一些实际内容.</p>
<p>本课的某些内容展示了
Together 的 LiveSource<sup>TM</sup>
实时同步技术.
这项技术是 Together
的长期特征,
给使用者留下了深刻印象.
玩得开心!</p>
<p><b>目录:</b></p>
<ul>
<li><a class="onPage" href="#classes">创建新类</a>
<li><a class="onPage" href="#onesource">LiveSource<sup>TM</sup>
实</a><a class="onPage" href="#onesource">时同步技术</a>
<li><a class="onPage" href="#edit">在 Together</a>
<a class="onPage" href="#edit">外部编辑源代码</a>
<li><a class="onPage" href="#attributes">增加特性(attributes)</a>
<li><a class="onPage" href="#operations">增加操作(operations)</a>
<li><a class="onPage" href="#views">修改</a><a class="onPage" href="#views">查看设置</a>
<li><a class="onPage" href="#properties">修改类属性</a>
<li><a class="onPage" href="#tips">技巧</a>
</ul>
<p class="head3"><img height="2" width="900" src="images/generic/rainbow2.gif"></p>
<p class="head3"><a name="classes"></a>创建新类 </p>
<p>下面是 <b>airline</b>
工程得最初需求.</p>
<ul>
<li>预定航班.
<li>购买机票.
<li>确定航班上是否还有足够的座位可以预定.
<li>计算航班的机票收入总数.</li>
</ul>
<p>从这些需求,
我们可以得到五个类.
下表中列出了这些类及其特性和操作.
这仅仅是一个开始.
继续深入下去,
你将发现需要更多的类和类成员.</p>
<table border="1" cellpadding="0" cellspacing="2">
<tr>
<td valign="top" bgcolor="#cccccc"><b>类</b></td>
<td valign="top"><b>FlightDescription</b></td>
<td valign="top"><b>ScheduledFlight</b></td>
<td valign="top"><b>Reservation</b></td>
<td valign="top"><b>Ticket</b></td>
<td valign="top"><b>Agent</b></td>
</tr>
<tr>
<td valign="top" bgcolor="#cccccc"><b>特性</b></td>
<td valign="top">departureTime<br>
arrivalTime<br>
origin<br>
destination<br>
capacity</td>
<td valign="top">date<br>
</td>
<td valign="top">name<font size="2"> </font>
<p></p>
</td>
<td valign="top">basePrice</td>
<td valign="top">name<br>
</td>
</tr>
<tr>
<td valign="top" bgcolor="#cccccc"><b>方法</b></td>
<td valign="top">getCapacity()<br>
setCapacity()</td>
<td valign="top">makeReservation()<br>
numberOfTickets()<br>
</td>
<td valign="top">ticketPurchased()<br>
calcPrice()<br>
</td>
<td valign="top">calcPrice()</td>
<td valign="top">makeReservation()<br>
</td>
</tr>
</table>
<p>开始工作前先在 Designer
面板中将 <b>ProblemDomain</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>ProblemDomain</b>
包中创建五个类: <b>FlightDescription</b>, <b>ScheduledFlight</b>, <b>Reservation</b>, <b>Ticket</b>,
和 <b>Agent</b>.</td>
</tr>
</table>
</td>
</tr>
</table>
<p>按 <Ctrl> 再点击 Designer
工具条<nobr>中的类按纽</nobr><nobr>(<img height="14" width="12" src="images/icons/classicon.gif" hspace="1" alt="Class button" align="top">)</nobr>以便创建多个类.
为类命名,
不需要书写任何类声明
-- Together 会自动生成代码.</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">当你在
Designer
面板中创建新类时,
Editor
面板将显示对应的新代码.<p>当你回到
<default> 模型图,
你将看到 <b>ProblemDomain</b>
包中显示了新建的类.
如果在某个模型图中进行修改,
则在相关模型图中也会有对应的显示.</p>
<p>下图是 <b>ProblemDomain</b>
包节点.
类名旁边的 +
表示类是 public 的.</p>
<p><img src="images/airline/problemdomainpkg.png" width="119" height="148" border="0" alt="Problem Domain Package" vspace="10" hspace="5"></p>
</td>
<td valign="top" bgcolor="white"><img src="images/airline/pro4_newclasses.png" width="513" height="461" border="0" alt="Diagram and editor panes" hspace="5"></td>
</tr>
</table>
</td>
</tr>
</table>
<p>Together
现在在包的物理目录中为类建立了源代码文件. Explorer
面板将把新类作为当前工程的一部分进行跟踪.</p>
<p><i>注意:</i>
虽然这个工程中没有内部类(inner
classes),
但创建内部类是很容易的.
只需要简单地将一个类拖动到另一个类内部即可.
或者你也可以在工具条上点击类按纽,
然后在 Designer
面板中的某个外部类上点击鼠标.</p>
<p>
<hr>
<p class="head3"><a name="onesource"></a>LiveSource<sup>TM</sup>
实时同步技术</p>
<p>Together
使用你的源代码来构建类图.
它不保留类图库.
当你在源代码中进行合法的修改时,
类图也会反映这些修改...
并且反过来也是如此.
在这一节和下一节中,
我们将向你展示如何修改工程中的部分元素,
以演示 Together 的 LiveSource<sup>TM</sup>
技术的工作状况.</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>
使用 Designer 面板将
<b>ScheduledFlight</b>
类改名为 <b>Flight</b>.</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<tr bgcolor="#cccccc">
<td bgcolor="#cccccc">
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td valign="top" bgcolor="white">
<table border="0" cellpadding="0" cellspacing="2" bgcolor="white">
<tr>
<td valign="top">可以<img src="images/airline/renameclass.gif" width="119" height="96" border="0" hspace="5" alt="Rename class" align="right">使用类的右键菜单来修改其名称.
或者在 Designer
面板中简单地双击类名即可.<p>Together
将更新代码,
文件名,
和类图.</p>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="2" bgcolor="white">
<tr>
<td valign="top"><img src="images/airline/pro4_renameineditor.png" width="323" height="152" border="0" alt="Editor pane" hspace="5" vspace="5"></td>
</tr>
</table>
</td>
<td valign="top" bgcolor="white">当你打开
<default> 模型图,
请注意 Together
已经更新了 <b>ProblemDomain</b>
包节点中的类名.
<p><img src="images/airline/renameinpackage.png" width="119" height="148" border="0" alt="Package node" hspace="5" vspace="10">
</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>
在 <default>
模型图中将 <b>ProblemDomain</b>
包改名为 <b>AirlinePD.</b></td>
</tr>
</table>
</td>
</tr>
</table>
<p>可以在 <default>
模型图中使用 <b>ProblemDomain</b>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -