⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib0043.html

📁 java外企软件工程师就业班 J2EE方向 《J2EE架构师手册》 电子书
💻 HTML
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Identifying Methods</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="LiB0042.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0044.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="204"></a><a name="ch06lev1sec5"></a>Identifying Methods</h2><p class="first-para">Methods are where the action is. Methods are invoked primarily when a user does something, when something that was scheduled occurs, and when something is received from an external interface. A common way to identify methods is to analyze each event and document the methods needed along the way. During the course of identifying the methods you'll need, you'll usually identify new classes.</p>
<p class="para">Starting with user actions, I use screens from the prototype to drive method identification. Consider an application login as an example. Most applications customize the main screen based on a user's identity and preferences. For the moment, assume that authorization and authentication is provided by the enterprise architecture and not at an application level. Further assume that you need to invoke something that will get user specifics from the security package, invoke something to retrieve that user's preferences regarding your application, and display the main application page.</p>
<p class="para">If you use Struts, you'll need some kind action class that can get user specifics from the security package, using the package to look up customer preferences (which will be used to generate the main page). If you haven't yet identified an action class to do this, add it to the model. Ignoring the security package itself, since it's out of scope, you then need a method some-where that allows the user preference look-up.</p>
<p class="para">Remember from our discussion of software layering in <a href="LiB0030.html#129" target="_parent" class="chapterjump">chapter 5</a> that classes in the presentation tier use deployment wrappers rather than using DAOs directly. Most applications identify a user object (or something similar) that manifests into a DAO class, a VO class, a business object, and a deployment wrapper for an enterprise bean. It would be logical to add a <a name="205"></a><a name="IDX-79"></a><span class="fixed">getUser(String userId)</span> method to our <span class="fixed">User</span> deployment wrapper. It would also be logical for that method to return a <span class="fixed">UserVO</span>, which includes information about preferences, as a result of the call. As a shortcut, assume that this method is added to the client proxy and all necessary components (controller interface and bean) of the deployment wrapper.</p>
<p class="para">
<b class="bold">Pass and return VOs instead of individual data items.</b> Doing so can increase performance when you use enterprise beans as a deployment wrapper. By reducing the number of methods that need to be changed, passing and returning VOs also reduces the amount of code that you'll need to change when you enhance the application.</p>
<p class="para">Deployment wrappers typically don't contain application logic but pass through to a business object. This method will have to be added to the business object as well. The deployment wrapper, when <span class="fixed">getUser()</span> is called, instantiates and calls a similar method on the business object, <span class="fixed">UserBus</span>.</p>
<p class="para">The physical look-up of the user preferences is usually delegated to at least one DAO. It would be logical to have a <span class="fixed">UserDAO</span> that has a <span class="fixed">select()</span> method on it that would do the look-up.</p>
<p class="para">By now, you're probably wondering why you don't just have the <span class="fixed">Action</span> class invoke the DAO directly. It would appear to be simpler because it would cut out several layers of classes that, in this example, appear to be adding little to the functionality of the product. Technically, you could have had the <span class="fixed">Action</span> class invoke the DAO directly, but doing so would have greatly added to the complexity of the <span class="fixed">Action</span> class, which isn't easy to debug, and would have eliminated the insulating benefits of software layering, as discussed in the last chapter.</p>
<p class="para">
<a class="internaljump" href="#ch06fig05">Figure 6.5</a> illustrates an object model for the example just discussed.</p>
<div class="figure">
<a name="206"></a><a name="ch06fig05"></a><span class="figuremediaobject"><a href="images/fig96%5F01%5F0%2Ejpg" NAME="IMG_16" target="_parent"><img src="images/fig96_01.jpg" height="306" width="317" alt="Click To expand" border="0"></a></span>
<br style="line-height: 1">
<span class="figure-title"><span class="figure-titlelabel">Figure 6.5: </span>Object Model Example</span>
</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="LiB0042.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0044.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 + -