📄 lib0070.html
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Common Mistakes</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="LiB0069.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0071.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="ch10"></a>
<div class="section">
<h2 class="first-section-title"><a name="330"></a><a name="ch10lev1sec3"></a>Common Mistakes</h2><p class="first-para">
<b class="bold">Populating VOs inconsistently.</b> I've seen some applications where fields of value objects were populated with different value sets depending on usage context. This practice is error prone and leads to bugs. It's also confusing for developers to maintain, especially if they weren't involved in the initial development effort. Usually, this practice is a red flag indicating that the design is process oriented instead of object oriented.</p>
<p class="para">
<b class="bold">Using a blank string to avoid a </b><b class="bold"><span class="fixed">NullPointerException</span></b>. Some developers initialize all fields to a blank string or something that means "null" but really isn't, as in the following:</p>
<div class="informalexample">
<pre class="literallayout">
private String _customerName = "";
</pre>
</div>
<p class="para">Although this kind of declaration eliminates <span class="fixed">NullPointerException <a name="331"></a><a name="IDX-134"></a>exceptions</span>, it doesn't prevent some other type of derivative exception from appearing down the line. This practice is akin to "sweeping dirt under the rug" and is best avoided.</p>
<p class="last-para">
<b class="bold">Maintaining parent-child relationships for VOs in both directions.</b> For example, the <span class="fixed">CustomerVO</span> would contain a collection of <span class="fixed">AccountVO</span> children, and each of the <span class="fixed">AccountVO</span> instances would contain a reference back to the parent. You run into the same problems with this practice as you do when you replicate data in relational databases. The result is double the maintenance when data is changed. Further, the practice is error prone and tends to be the root cause of bugs.</p>
</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="LiB0069.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0071.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 + -