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

📄 lib0032.html

📁 j2ee架构师手册
💻 HTML
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Value Object Layer</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="LiB0031.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0033.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="ch05"></a>
<div class="section">
<h2 class="first-section-title"><a name="151"></a><a name="ch05lev1sec3"></a>Value Object Layer</h2><p class="first-para">Every application has data items that logically belong and typically are used together. It's programmatically convenient and, with enterprise beans, performance enhancing to treat this logical group of data items as a separate object. This type of object is commonly known as a value object (VO), although some texts refer to it as a data transfer object. If Java had a "structure" construct, as C/C++ and many other languages do, a VO would be a structure.</p>
<p class="para">For example, you could combine various pieces of information for a report template into a VO. Methods needing a report template argument could then accept the <span class="fixed">ReportTemplateVO</span> instead of individual arguments for all components of the structure.</p>
<p class="para">Typically, a VO has accessors and mutators but little else. And usually a VO implements <span class="fixed">java.io.Serializable</span> so it can be transmitted to remote application clients. J2EE containers and RMI services serialize the content of Java classes before transmitting them to a remote machine. A common convention is to give value object names a VO suffix, as in <span class="fixed">CustomerVO</span>.</p>
<div class="section">
<h3 class="sect3-title">
<a name="152"></a><a name="ch05lev2sec4"></a>Common Patterns</h3>
<p class="first-para">The value object originates from a formally defined pattern. In some texts, this pattern is called the value object pattern (<a href="LiB0037.html#180" target="_parent" class="chapterjump">Alur, Crupi, and Malks, 2001</a>). The VO pattern enhances EJB performance but is useful in communication among all layers of the application.</p>

<p class="para">You can combine the VO pattern with the composite pattern, which is used when something contains other things. For instance, a report template often contains multiple parameters. Using the composite pattern, the <span class="fixed">ReportTemplateVO</span> contains an array of <span class="fixed">ReportTemplateParameterVO</span> objects, as illustrated in <a class="internaljump" href="#ch05fig04">figure 5.4</a>.</p>
<div class="figure">
<a name="153"></a><a name="ch05fig04"></a><span class="figuremediaobject"><a href="images/fig76%5F01%5F0%2Ejpg" NAME="IMG_5" target="_parent"><img src="images/fig76_01.jpg" height="400" width="313" alt="Click To expand" border="0"></a></span>
<br style="line-height: 1">
<span class="figure-title"><span class="figure-titlelabel">Figure 5.4: </span>Composite Pattern with Value Object Context</span>
</div>
</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="LiB0031.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0033.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 + -