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

📄 lib0033.html

📁 j2ee架构师手册
💻 HTML
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Business Logic 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="LiB0032.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0034.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="154"></a><a name="ch05lev1sec4"></a>Business Logic Layer</h2><a name="155"></a><a name="IDX-60"></a>
<p class="para">Objects in the business logic layer combine data with business rules, constraints, and activities. Business objects should be separated from DAOs, VOs, and the deployment layer, such as enterprise beans, to maximize the possibility of reuse. Business objects often use and coordinate the activities of multiple data access objects.</p>
<p class="para">
<b class="bold">Business objects should be deployment independent and self-contained.</b> Any Java Naming and Directory Interface (JNDI) resource (e.g., database connections) that a business object needs to function should be provided by its deployment wrapper. This allows business objects to be redeployed (or <a name="156"></a><a name="IDX-61"></a>republished, if you will) as anything you would like, including enterprise beans, RMI services, CORBA services, Web services, applets, and applications.</p>

<p class="para">Some developers add the <span class="fixed">BO</span> suffix to business object names, but this is not a technical requirement.</p>
<div class="section">
<h3 class="sect3-title">
<a name="157"></a><a name="ch05lev2sec5"></a>Common Patterns</h3>
<p class="first-para">Layered initialization is a pattern you will commonly use when you have different varieties of the same object. For example, most applications have different types of users. As shown in <a class="internaljump" href="#ch05fig05">figure 5.5</a>, you might have trust customer users, corporate customer users, banking support users, application administrator users, and so on. All these users share commonality but also have aspects that are unique.</p>
<div class="figure">
<a name="158"></a><a name="ch05fig05"></a><span class="figuremediaobject"><a href="images/fig77%5F01%5F0%2Ejpg" NAME="IMG_6" target="_parent"><img src="images/fig77_01.jpg" height="127" width="350" alt="Click To expand" border="0"></a></span>
<br style="line-height: 1">
<span class="figure-title"><span class="figure-titlelabel">Figure 5.5: </span>Layered Initialization Pattern Example</span>
</div>
<p class="para">When the same business object might have to produce different outputs or use different inputs, you will most likely use the adapter pattern. Consider the example shown in <a class="internaljump" href="#ch05fig06">figure 5.6</a>, a reporting business object that has several different delivery mechanisms&#8212;e-mail, printing, Web site publishing&#8212;but all other processing is the same. Having an adapter to represent the input consolidates a lot of code.</p>
<div class="figure">
<a name="159"></a><a name="ch05fig06"></a><span class="figuremediaobject"><a href="images/fig78%5F01%5F0%2Ejpg" NAME="IMG_7" target="_parent"><img src="images/fig78_01.jpg" height="183" width="350" alt="Click To expand" border="0"></a></span>
<br style="line-height: 1">
<span class="figure-title"><span class="figure-titlelabel">Figure 5.6: </span>Adapter Pattern Example</span>
</div>
<p class="para">Like the adapter pattern, the strategy pattern is used when the activities of a business object are likely to vary according to the context. However, the adapter pattern leaves the activities of a class constant while dynamically varying its inputs and outputs, and the strategy pattern makes the activities of a class dynamic while using constant inputs and outputs. It's largely a difference in perception of "who's the client." <a class="internaljump" href="#ch05fig07">Figure 5.7</a> illustrates the strategy pattern.</p>
<div class="figure">
<a name="160"></a><a name="ch05fig07"></a><span class="figuremediaobject"><a href="images/fig78%5F02%5F0%2Ejpg" NAME="IMG_8" target="_parent"><img src="images/fig78_02.jpg" height="306" width="350" alt="Click To expand" border="0"></a></span>
<br style="line-height: 1">
<span class="figure-title"><span class="figure-titlelabel">Figure 5.7: </span>Strategy Pattern Example</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="LiB0032.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0034.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 + -