📄 lib0039.html
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Identifying Objects</title>
<link rel="STYLESHEET" type="text/css" href="images/xpolecat.css">
<link rel="STYLESHEET" type="text/css" href="images/ie.content.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle" alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0038.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0040.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
<br>
<div class="chapter">
<a name="ch06"></a>
<div class="section">
<h2 class="first-section-title"><a name="188"></a><a name="ch06lev1sec1"></a>Identifying Objects</h2><p class="first-para">
<b class="bold">Identify the most important constructs.</b> Nouns in use cases are generally good candidates for classes. Thus a good way to start identifying objects is by reading the use cases and extracting a list of all the nouns. (You can ignore <i class="emphasis">system</i> in the beginning phrase, "The system will," because it's merely part of the use-case format.)</p>
<a name="189"></a><a name="IDX-73"></a>
<p class="para">At this point, you should interpret my use of the word <i class="emphasis">object</i> loosely. In the early stages of development, it's impossible to know enough about these objects to understand exactly which classes you will derive from them. Note that my use of the term <i class="emphasis">object</i> differs from some texts that use the term to refer to an instance of a class.</p>
<p class="para">
<b class="bold">Don't bother with attribution or relationships at this stage.</b> Attribution and relationships are important, but identifying them too early will bog you down in too much detail and will throw the team into frequent tangents. For now, try not to be concerned about process and focus instead on data organization.</p>
<p class="para">
<b class="bold">As objects are identified, record persistence requirements.</b> Some classes will represent data that your application has to store, usually in a database, and are said to be <b class="bold">persistent</b>. In fact, persistent objects frequently appear as entities in the data model. I often record objects with persistent data as entities in the data model as they're identified in the object model. I discuss data modeling in detail in <a href="LiB0047.html#216" target="_parent" class="chapterjump">chapter 7</a>.</p>
<p class="para">
<b class="bold">Objects identified at this stage are high level.</b> You will further refine and expand them later in the process, using objects to determine specific classes.</p>
<div class="section">
<h3 class="sect3-title">
<a name="190"></a><a name="ch06lev2sec1"></a>Object Identification Example</h3>
<p class="first-para">Let's use an example paraphrased from a reporting system I once implemented. The team defined the following uses cases:</p>
<ul class="itemizedlist">
<li class="first-listitem">
<p class="first-para">The system will provide an interface that will accept report template definitions from an existing MVS/CICS application. A report template consists of an ID, a name, a list of parameters required to run the template, and a list of data items produced by the template.</p>
</li>
<li class="listitem">
<p class="first-para">The system will allow application administrators to control the report templates that users belonging to a trust customer organization can run.</p>
</li>
<li class="listitem">
<p class="first-para">The system will run reports at least as fast as its predecessor system did on average.</p>
</li>
<li class="listitem">
<p class="first-para">The system will restrict reported data for all trust customer users to that of the trust customer organization to which they belong.</p>
</li>
<li class="listitem">
<p class="first-para">The system will allow banking support users to execute all report templates using data from any trust customer organization.</p>
</li>
</ul>
<a name="191"></a><a name="IDX-74"></a>
<p class="para">Looking at the nouns in the use cases in order (ignoring <i class="emphasis">system</i>, as mentioned earlier) gave us the list that appears in the first column of <a class="internaljump" href="#ch06table01">table 6.1</a>.</p>
<a name="192"></a><a name="ch06table01"></a>
<table class="table" border="1">
<caption class="table-title">
<span class="table-title"><span class="table-titlelabel">Table 6.1: </span>Object Identification Example</span>
</caption>
<thead>
<tr valign="top">
<th class="th" scope="col" align="left">
<p class="table-para">
<b class="bold">Noun (fromuse case)</b>
</p>
</th><th class="th" scope="col" align="left">
<p class="table-para">
<b class="bold">Object</b>
</p>
</th>
</tr>
</thead>
<tbody>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Interface</p>
</td><td class="td" align="left">
<p class="table-para">
<span class="fixed">ReportTemplateInterface</span>
</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Report template</p>
</td><td class="td" align="left">
<p class="table-para">
<span class="fixed">ReportTemplate</span>
</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">List of parameters</p>
</td><td class="td" align="left">
<p class="table-para">
<span class="fixed">ReportTemplateParameter</span>
</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Data item</p>
</td><td class="td" align="left">
<p class="table-para">
<span class="fixed">ReportDataItem</span>
</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Application administrator</p>
</td><td class="td" align="left">
<p class="table-para">
<span class="fixed">ApplicationAdministrator</span>
</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Trust customer organization</p>
</td><td class="td" align="left">
<p class="table-para">
<span class="fixed">TrustCustomerOrganization</span>
</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Trust customer user</p>
</td><td class="td" align="left">
<p class="table-para">
<span class="fixed">TrustCustomerMember</span>
</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Reported data</p>
</td><td class="td" align="left">
<p class="table-para">
<span class="fixed">Report</span>
</p>
</td>
</tr>
<tr valign="top">
<td class="td" align="left">
<p class="table-para">Banking support user</p>
</td><td class="td" align="left">
<p class="table-para">
<span class="fixed">BankingSupportUser</span>
</p>
</td>
</tr>
</tbody>
</table>
<p class="para">Next we rephrased the nouns to make them self-contained object names, as shown in <a class="internaljump" href="#ch06table01">table 6.1</a>. By self-contained, I mean that object names shouldn't depend on context to provide meaning. For instance, <i class="emphasis">interface</i> from the first use case became <span class="fixed">ReportTemplateInterface</span> and <i class="emphasis">list of parameters</i> became <span class="fixed">ReportTemplateParameter</span>. The fact that our use case referred to a "list" of parameters was documented as a relationship. The more descriptive the object name, the better. All the objects were persistent except <span class="fixed">ReportTemplateInterface</span>. (Note that the word <i class="emphasis">interface</i> in this use case refers to an application interface and may not imply use of a Java interface construct.)</p>
<p class="para">Three types of users appear in the list: application administrator, trust customer member, and banking support user. When we got to attribution, we recognized that there was another object, User, with different subtypes. Inheritance relationships like this are easier to recognize when it comes time for attribution, so let's leave the object list as it is for now.</p>
<p class="para">An alternative to merely identifying nouns is to do the data-modeling exercise first. All identified entities are good object candidates. Many of the objects we identified in this example would make good entity candidates as well. See <a href="LiB0047.html#216" target="_parent" class="chapterjump">chapter 7</a> for details.</p>
<p class="last-para">Some of these objects were implemented as classes in multiple software layers in the application. This process is the focus of the <a href="LiB0040.html#193" target="_parent" class="chapterjump">next section</a>. Defining and illustrating these layers was described in <a href="LiB0030.html#129" target="_parent" class="chapterjump">chapter 5</a>.</p>
</div>
</div>
</div><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle" alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0038.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0040.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -