<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Daniel Pitts' Tech Blog &#187; Program Design</title>
	<atom:link href="http://virtualinfinity.net/wordpress/category/program-design/feed/" rel="self" type="application/rss+xml" />
	<link>http://virtualinfinity.net/wordpress</link>
	<description>Daniel Pitts' Tech Blog</description>
	<lastBuildDate>Thu, 04 Feb 2010 19:10:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Levels of Error Handling</title>
		<link>http://virtualinfinity.net/wordpress/program-design/2009/11/29/levels-of-error-handling/</link>
		<comments>http://virtualinfinity.net/wordpress/program-design/2009/11/29/levels-of-error-handling/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 02:15:30 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Program Design]]></category>
		<category><![CDATA[abstraction]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[business layer]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[error handling]]></category>
		<category><![CDATA[humans]]></category>
		<category><![CDATA[Object Oriented Design]]></category>

		<guid isPermaLink="false">http://virtualinfinity.net/wordpress/?p=69</guid>
		<description><![CDATA[If you have been using computers for any amount of time, you&#8217;ve come across an error message.  From nearly useless &#8220;access violation&#8221; dialog boxes, to the more helpful &#8220;User names must not contain spaces&#8221; form messages, error messages are frequent on computers.  Whether you&#8217;re a Mac, PC, Penguin, or Other, error messages that mean only [...]]]></description>
			<content:encoded><![CDATA[<p>If you have been using computers for any amount of time, you&#8217;ve come across an error message.  From nearly useless &#8220;access violation&#8221; dialog boxes, to the more helpful &#8220;User names must not contain spaces&#8221; form messages, error messages are frequent on computers.  Whether you&#8217;re a Mac, PC, Penguin, or Other, error messages that mean only &#8220;something broke&#8221; are frustrating.</p>
<p>Programmers often treat all kinds of errors the same, especially when a user interaction is involved.  The problem is, not all errors have the same &#8220;meaning&#8221;, and not all errors should be handled the same way.  If, as a User, I attempt to use the program for something, and it reports a message target at a programmer (displaying a stack-trace, for instance), it can be confusing.  As a High-Level programmer, if a library call fails but my code gets back few details (getting only &#8216;There was an SQL error&#8217;, without the SQL statement that caused the error), it can be just as frustrating.</p>
<h3>What do you mean by low-level or high level?</h3>
<p>There usually different &#8220;levels&#8221; to an application, and each level has a specific type of concern.  Errors on lower levels should be filtered up in as appropriate a manor as possible, so that the higher levels can handle them as gracefully as possible.  Applications can have many different layers, but conceptually they can usually be represented in exactly four levels. What are those four layers? I&#8217;m glad you asked, because I&#8217;ve listed them below, from highest to lowest.</p>
<dl>
<dt>The User</dt>
<dd> This, of course, is the person using your application. Most often they are a human being, but someday users may include Artificial Intelligence or Extra Terrestrial entities.  Users are often task-oriented, although some of them are naturally explorers.  Task-Oriented users are more damaged by unexpected errors. Exploring users are more interested in seeing what is and isn&#8217;t possible, so errors often define a boundary for them, but these users are also most likely to find bugs in your application. </dd>
<dt>High-Level Code</dt>
<dd> This is sometimes called the &#8220;Domain&#8221; level.  The public methods in these classes are often task-oriented, and the class often define nouns that the User would be able to identify with.  Code in this level translates between user requests and low-level requests. This is of course an idealized definition, but the closer to this definition you can make your reality, the easier to maintain your application will be. </dd>
<dt>Low-Level Code</dt>
<dd> This is the library or framework code.  Code in this level usually is used to handle resources, and to actually get things done.  Most Low-Level code is &#8220;possibility&#8221; oriented. The API defined allows you to do simple, atomic, operations that might not be meaningful on their own, but can be strung together in a useful manor. </dd>
<dt>Resources</dt>
<dd> These are &#8220;external&#8221; things used by the application. Some examples are memory, files, databases, and sockets . Consumable (memory, disk-space, etc&#8230;) resources can run out unexpectedly, even if you &#8220;check&#8221; before hand.  Many resources fail for various reasons, for example sockets might fail because of a disconnected wire, files might fail because of a physical disk error, and database operations might fail due to overloaded CPU or low available memory. </dd>
</dl>
<p>Note, that there can be some &#8220;blurring&#8221; of levels, depending on the project you are working on.  For example, the developer of an HTTP Client library is probably writing &#8220;high-level&#8221; code, in that it represents the domain of HTTP, and provides &#8220;task-oriented&#8221; interfaces.  However, when that HTTP Client library is used in an application, it becomes &#8220;low-level&#8221;, because the User probably doesn&#8217;t care about the HTTP Protocol, and instead only cares about &#8220;downloading a file&#8221; or &#8220;viewing a web-page&#8221;.</p>
<p>From my experience, each of the levels correspond to a different kind of error, and those errors should all be handled differently. The likelihood of most of the types of errors can be managed, but not eliminated completely.</p>
<h3>Error Handling</h3>
<h4>Handling User errors</h4>
<p>This is the highest-level error.  It is caused by a user doing something they shouldn&#8217;t.  Most commonly this means the user entered an invalid input somewhere.  Whenever possible, the User Interface should be designed to prevent user errors.  For example, if you need a date then you provide a &#8220;Date Widget&#8221; and if you need a number you disallow non-numeric input.</p>
<p>Sometimes, it isn&#8217;t feasible to simply &#8220;prevent&#8221; user error.  In this case, the user input must be validated.  The best place to validate it is in the High-Level code.  Since this code is closest to the user, it has more knowledge about the user.  The High-Level code knows whether to pop-up a dialog box, print a line to the console, or update a form with error messages.</p>
<p>It may sometimes useful abstract the &#8220;error reporting&#8221; interface, so that it can be reused by different  UI interfaces. For example, domain level code might be used in a Web App, as well as a native GUI app, or even a command-line app.  Having an reusable interface for reporting multiple user errors helps in porting to new user interfaces.</p>
<p>Usually, it should be considered a bug in the high-level code if invalid user input causes a lower level exception. Low-Level code must verify the input it receives from higher-level code.</p>
<p>There are times, however, when it is infeasible to verify before hand whether an input is valid, and the validation must be handled a lower-level code.  In this case, the lower-level code should report the error to the higher level code, which should handle it and pass that information on to the user in an appropriate manor.</p>
<h4>Handling Bugs</h4>
<p>Bugs can happen in either low-level code, or high-level code.</p>
<p>In High-Level code, it means that some method (often a user task-oriented method) has violated some constraint, or failed to handle a lower-level error. In Low-Level code<br />
it means that a method (part of a framework or library) has violated some constraint, or failed to properly handle a Resource Error.</p>
<p>First and foremost, it is rarely appropriate to show all the detail of &#8220;bug&#8221; caused errors to the user.  Most users would prefer not to experience bugs at all, but because this is the real world, we have to handle the bugs some how.  Most times, its enough to tell the user &#8220;There was an internal error.  Click &#8216;Report&#8217; to send a bug report.&#8221;  The bug report should include any useful state information, but absolutely must include a full stack trace.  If possible, the high-level state should be recoverable, so that the user doesn&#8217;t lose any of their work, and can try either a slightly different approach, or wait for a bug fix.</p>
<p>The number of errors of these kinds can be reduced by Unit Testing, improving API design, Integration Testing, and User Testing.</p>
<h4>Resource errors</h4>
<p>These are Exceptional Circumstances.  Resource errors can be caused by bad data, connectivity issues, database constraint violations, file corruption, file-not-found, out-of-memory, and many more uncontrollable problems.</p>
<p>Resource errors should be reported to the user with as much detail as is likely to be useful to them.  If the user specifies a file, and that file is in the wrong format, this could be treated as a user error, and the user should be informed of the file they chose, and what was wrong with it.  Low-level code should report to higher-level code something along the lines of &#8220;I expected a FOO file,&#8221; and the higher-level code should report something like &#8220;The file c:\my.bar is not a FOO file. &#8220;  If a file can not be found, an appropriate message should be displayed, etc&#8230;</p>
<p>For this reason, low-level code which handles resources should report errors with as much structured information as feasible to higher-level code.  The higher-level code can then query that structure and produce an error message which is appropriate for the user.  For example, an SQL error at the lower level might mean different things; Typically duplicate a record might a User Error, but a syntax error is likely Low-Level Programmer Error.</p>
<p>There is far less that can be done to reduce resource errors, as they are often caused by external circumstances.  Often times using redundancy can reduce the frequency of fatal errors, but the errors themselves will still occur, and should still be handled appropriately.</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualinfinity.net/wordpress/program-design/2009/11/29/levels-of-error-handling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing Bugs</title>
		<link>http://virtualinfinity.net/wordpress/program-design/2008/05/20/fixing-bugs/</link>
		<comments>http://virtualinfinity.net/wordpress/program-design/2008/05/20/fixing-bugs/#comments</comments>
		<pubDate>Tue, 20 May 2008 23:06:38 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Program Design]]></category>
		<category><![CDATA[ambiguity]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[mistakes]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://virtualinfinity.net/wordpress/?p=37</guid>
		<description><![CDATA[The best way to fix a bug is to prevent the bug in the first place. There are several fundamental causes of bugs which we can explore. One very common cause of bugs is miscommunication. This is really not a bug, but an unimplemented feature; if there was a requirement that wasn&#8217;t met, it is [...]]]></description>
			<content:encoded><![CDATA[<p>The best way to fix a bug is to prevent the bug in the first place.  There are several fundamental causes of bugs which we can explore.</p>
<p>One very common cause of bugs is miscommunication.  This is really not a bug, but an unimplemented feature; if there was a requirement that wasn&#8217;t met, it is often labeled as a bug.  It really could have been a misunderstanding of what the requirement actually was, or even that there was a requirement at all. No one is to blame, but that doesn&#8217;t mean someone couldn&#8217;t have prevented it.  If you think there is a missing requirement, bring it up.  If you don&#8217;t understand a requirement, get it clarified.</p>
<p>Bad assumptions can also lead to bugs.  Specifically, if you assume that some external API will handle all the cases you need it to, but for at least one case the behavior isn&#8217;t what you assumed, you have a bug.  It can be hard to determine for this whether the bug is in your code or the external code. Usually that can be determined by the documentation of the third party code.  If its not documented, its undefined.</p>
<p>Ambiguity can lead to bad assumptions.  If the documentation is ambiguous, try looking in the source, or writing a unit test.  Update the documentation to be less ambiguous if you have access.  Also make sure to add assertions to your code.</p>
<p>Mistakes happen.  A bug can be the result of a simple mistake.  Sometimes you type one thing while you&#8217;re thinking something else. If you were (un)lucky enough to type something the compiler was okay with, a bug is born.  eg, A common bug in c and c++ is the =/== bug  where &#8220;<code>if (i = 1)</code>&#8221; is an (=) assignment, but was probably meant as an (==) comparison.</p>
<p>What was I writing about? Forgetfulness might also lead to bugs.  &#8220;Oh, I&#8217;ll just fill this method out later,&#8221; or &#8220;I&#8217;ll write the &#8216;else&#8217; case tomorrow.&#8221;  Judicious use of &#8220;TODO&#8221; comments and the like can help with this problem.</p>
<p>&#8220;That does not compute.&#8221; Sometimes, there isn&#8217;t a bug, per se, but your algorithm fails in certain cases.  Maybe the case is impossible to solve in human-scale times, maybe you&#8217;re using a heuristic that has a flaw.  These kinds of &#8220;bugs&#8221; are harder to solve, since the programmer has done everything right.   Research other algorithms, or put in checks to verify (as much as possible) the input will work with the algorithm.</p>
<p>And as such, these bugs get into the code base.  The next phase should filter out bugs.  The testing phase.  How do bugs progress from codebase into production systems?</p>
<p>Murphy&#8217;s law applies a few ways to testing.  There is always &#8220;the tiniest little change that couldn&#8217;t possibly cause any problems.&#8221;  If you don&#8217;t test after making it, it will cause a problem.</p>
<p>Unit testing can do a lot to verify that one unit works for the tested use cases. Sometimes the unit test doesn&#8217;t find bugs that come from complex interactions between two separate units, or the unit test doesn&#8217;t actually test all cases.</p>
<p>Putting your product in front of a user can help you find more bugs. Murphy&#8217;s law as it applies: The first thing a user will do is the only combination of things you didn&#8217;t test. That combination will fail.  This is not a bad thing though. It lets you know exactly what unit-test you forgot to write.  Don&#8217;t just fix the bug, fix the test.  Write a test that fails for that series of actions, and <em>then </em>make the code work correctly.</p>
<p>No code will ever be 100% bug free.  If it is 100% bug free, it probably isn&#8217;t very useful.  Of course, this is a generalization, but it is often the case.  Don&#8217;t become discouraged because of bugs.  Fix them one at a time, and document the ones you won&#8217;t fix in this release as &#8220;unsupported features&#8221;.  If you think a poor design is causing the easy of creating bugs, or a better design would prevent them, then go ahead and consider refactoring.  Just know that a new design will have new bugs too.  They may be easier to spot and easier to fix, so don&#8217;t rule the redesign out flat.</p>
<p>So now we know the reasons bugs get created, how do we find their cause?</p>
<p>Causality.  We know of the existence of a bug because of its effect. A number is wrong, or we get a NullPointerException, or Mr. Smith gets Mrs. Robinson&#8217;s bill.  Where in the codebase should the &#8220;correct&#8221; behavior be?  Look there, add debug logging or break points of some sort.  Assert your assumptions and watch what happens.  What if that code appears to be doing the right thing?  Maybe the bug happens before that point.  From where in the codebase does this behavior get invoked?  Repeat the process there.  Feel free to use &#8220;gut&#8221; intuition to find where you think the bug is, but verify that the bug is there before &#8220;fixing&#8221; it.</p>
<p>Also, no bug is so old that it can&#8217;t be fixed.  Even <a title="The 25 Year Old BSD Bug" href="http://osnews.com/story/19731/The-25-Year-Old-UNIX-Bug">25 year old BSD bugs</a> can be found and fixed.</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualinfinity.net/wordpress/program-design/2008/05/20/fixing-bugs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Look, in the sky! It&#8217;s a Relation; It&#8217;s an Object System; No, It&#8217;s a Graph!</title>
		<link>http://virtualinfinity.net/wordpress/program-design/2008/03/13/objects-and-relations-as-graphs/</link>
		<comments>http://virtualinfinity.net/wordpress/program-design/2008/03/13/objects-and-relations-as-graphs/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 04:30:09 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Program Design]]></category>
		<category><![CDATA[graph theory]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[object system]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[rdbms]]></category>
		<category><![CDATA[relational]]></category>

		<guid isPermaLink="false">http://virtualinfinity.net/wordpress/program-design/2008/03/13/objects-and-relations-as-graphs/</guid>
		<description><![CDATA[Sometimes when dealing with OO design in conjunction with relational persistence (RDBMS), it becomes difficult to reconcile the differences between the two and still maintain a consistent approach. The problem that I seem to run into time and again is that I&#8217;m an OO programmer first.  I tend to think of things top-down.  What&#8217;s the [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes when dealing with OO design in conjunction with relational persistence (RDBMS), it becomes difficult to reconcile the differences between the two and still maintain a consistent approach.</p>
<p>The problem that I seem to run into time and again is that I&#8217;m an OO programmer first.  I tend to think of things top-down.  What&#8217;s the overall system look like? What are the large pieces? What fits &#8220;in&#8221; those large pieces?</p>
<p>When you work this way, you tend to end up with a tree of objects or even more complex graph of objects.  The interesting thing about a graph of objects is that it is, above all else, a graph, and there are many ways to represent graphs.</p>
<p>Fundamentally, all graphs are a set of Nodes and (directed) Edges, lets examine a few common ways to represent nodes and edges.</p>
<ul>
<li>Each node knows which other nodes it connects to. In other words, the nodes know there out-going edges. This is close to how most common OO programming languages work; an object is the node, and any reference to another object is a one-way edge.</li>
<li>Each node knows which other node connects to it. The nodes know about there in-coming edges. This is the strict opposite of the above. It is also common in relation models with one-to-one relationships.</li>
<li>A list of nodes and a list of edges are maintained independently from each other.  This is common in relational models with many-to-many relationships.</li>
<li>A combination of all of the above.</li>
</ul>
<p>Any graph can be represented in any one of the above ways (as well as many others).  This is important to realize, because it gives you the ability to refactor an OO design into something that better fits the relational model.  There will always be a disconnect between OO and RDBMS, because they look at design in fundamentally different ways, but that doesn&#8217;t mean you can&#8217;t work with both of them in the same system, leveraging their individual strengths.</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualinfinity.net/wordpress/program-design/2008/03/13/objects-and-relations-as-graphs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Assembly line: Separation of concerns with Inversion of Control.</title>
		<link>http://virtualinfinity.net/wordpress/program-design/2008/02/01/assembly-line-separation-of-concerns-with-inversion-of-control/</link>
		<comments>http://virtualinfinity.net/wordpress/program-design/2008/02/01/assembly-line-separation-of-concerns-with-inversion-of-control/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 21:33:20 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Program Design]]></category>
		<category><![CDATA[decoupling]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[inversion of control]]></category>
		<category><![CDATA[maintainability]]></category>
		<category><![CDATA[Object Oriented Design]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[separation of concerns]]></category>

		<guid isPermaLink="false">http://virtualinfinity.net/wordpress/program-design/2008/02/01/assembly-line-separation-of-concerns-with-inversion-of-control/</guid>
		<description><![CDATA[If you decide to go the route of using Inversion of Control and Dependency Injection, it can make your program a lot more flexible. If you do this manually, you&#8217;ll find that even a complex system can be managed well this way. A common idiom is to use Dependency Injection to separate the creation of [...]]]></description>
			<content:encoded><![CDATA[<p>If you decide to go the route of using <a href="http://en.wikipedia.org/wiki/Inversion_of_control" title="Inversion of Control - Wikipedia, the free encyclopedia">Inversion of Control</a> and <a href="http://en.wikipedia.org/wiki/Dependency_injection" title="Dependency Injection - Wikipedia, the free encyclopedia">Dependency Injection</a>, it can make your program a lot more flexible.  If you do this manually, you&#8217;ll find that even a complex system can be managed well this way.</p>
<p>A common idiom is to use Dependency Injection to separate the creation of the object from the use of the object.  The client object has some way to receive other objects it needs to &#8220;talk&#8221; to, but the client object doesn&#8217;t care how they were created:</p>
<pre class="code">class MyClient {
   MyFooService fooService;
   MyBarService barService;
   public MyClient(MyFooService fooService, MyBarService barService) {
      this.fooService = fooService;
      this.barService = barService;
   }

   public void doStuff() {
      fooService.iLikeFooFighters();
      barService.buyRoundsForEveryone();
   }
}</pre>
<p>From this code snippet, FooService and BarService could be interfaces, abstract classes, or even concrete classes. If you change your mind later about them, MyClient doesn&#8217;t have to change <em>at all</em></p>
<p>Another common approach for DI is to use setter based injection. This approach is useful for complex object graphs that have cyclic dependencies.  I&#8217;ll leave it as an exercise for the reader to re-write MyClient with setters.</p>
<p>So, in this phase one, you&#8217;ve separated the concern of object creation and wiring from object usage.  It is perfectly acceptable to stop here.  However, depending on how complicated your object system is, you may wish to separate the concerns even further.  You can do this via the Builder pattern (nb. The current Wikipedia entry on Builder pattern is incorrect and misleading.)</p>
<p>With the builder pattern, you separate the concern of creation from the concern of &#8220;wiring&#8221;.  The builder accepts a series of objects that belong in a graph.  The builder knows how to connect the objects through DI, but doesn&#8217;t care where the objects came from or how they were created/configured.</p>
<p>In a recent project of mine, I had to create a Robot instance, and wire it with a <strong>lot</strong> of components. To make things worse, some of the components also needed sub-components, and some components needed to know about other components, and some needed to know about the robot itself.  I had successfully created a class that would create the components and wire them together, but it was a bit fragile (do things in the wrong order and you get an NPE, since not all of the components were created yet).</p>
<p>To solve this design issue, I created a class (HardwareContext), which held a reference to every component that it takes to build a robot.  Those fields were populated using setter based dependency injection.  Once those references are all created, hardwareContext.wireRobot() is called, and that is where all of the object graph is connected.  This would allow me to create a new hardware context that wired the components differently if I needed to. It also allows me to create a new HardwareSpecification (the class that creates components), which creates different configurations for the robot.</p>
<p>This leads to a highly extensible and configurable system.  It also makes it easy to figure out where to add a line of code. If the line is doing wiring, it goes into the Context, if it is creating an object, it belongs in the Spec.  Easy, clean, clear.</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualinfinity.net/wordpress/program-design/2008/02/01/assembly-line-separation-of-concerns-with-inversion-of-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sensitivity: A Case for Convention.</title>
		<link>http://virtualinfinity.net/wordpress/program-design/2008/01/28/a-case-for-convention/</link>
		<comments>http://virtualinfinity.net/wordpress/program-design/2008/01/28/a-case-for-convention/#comments</comments>
		<pubDate>Mon, 28 Jan 2008 20:29:46 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Program Design]]></category>
		<category><![CDATA[case sensitivity]]></category>
		<category><![CDATA[cross-platform]]></category>
		<category><![CDATA[portability]]></category>
		<category><![CDATA[Windows sucks]]></category>

		<guid isPermaLink="false">http://virtualinfinity.net/wordpress/program-design/2008/01/28/a-case-for-convention/</guid>
		<description><![CDATA[Image this. You develop a Java application that uses only standard Java features. It only uses a hand full of classes, so you just distribute individually. It works great until someone using windows runs your program. &#8220;Why am I getting &#8216;Exception in thread &#8220;main&#8221; java.lang.NoClassDefFoundError: FOO (wrong name: Foo)&#8217;?&#8221; Remember, Java is case sensitive, but [...]]]></description>
			<content:encoded><![CDATA[<p>Image this.  You develop a Java application that uses only standard Java features. It only uses a hand full of classes, so you just distribute individually.  It works great until someone using windows runs your program.</p>
<p>&#8220;Why am I getting &#8216;Exception in thread &#8220;main&#8221; java.lang.NoClassDefFoundError: FOO (wrong name: Foo)&#8217;?&#8221;<br />
Remember, Java is case sensitive, but the Windows file system is *not*.</p>
<pre class="code">public class Foo {
  public static void main(String...args) {
    new FOO();
  }
}

class FOO {
  public FOO() {
    System.out.println("Works like a charm.");
  }
}</pre>
<p>When you compile this on Linux, you get &#8220;Foo.class&#8221; and &#8220;FOO.class&#8221;, but on Windows, you only get one file.  Oops!</p>
<p>So, its always a good idea to follow good convention with regards to capitalization.  Use CamelCase, and treat abbreviations as words.  Use XmlParser rather than XMLParser.  Note that some of the standard Java API doesn&#8217;t do that (URL for instance).</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualinfinity.net/wordpress/program-design/2008/01/28/a-case-for-convention/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Art of Decoupling.</title>
		<link>http://virtualinfinity.net/wordpress/program-design/2007/12/03/the-art-of-decoupling/</link>
		<comments>http://virtualinfinity.net/wordpress/program-design/2007/12/03/the-art-of-decoupling/#comments</comments>
		<pubDate>Mon, 03 Dec 2007 19:47:59 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Program Design]]></category>
		<category><![CDATA[decoupling]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[maintainability]]></category>
		<category><![CDATA[Object Oriented Design]]></category>
		<category><![CDATA[over-design]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[refactoring]]></category>

		<guid isPermaLink="false">http://virtualinfinity.net/wordpress/program-design/2007/12/03/the-art-of-decoupling/</guid>
		<description><![CDATA[Some people think the power of OO design is that the classes represent real-life concepts that are easier for a human to understand. Others think that its power comes from code reuse. Still other just accept OO as the paradigm that they are supposed to use, simply because they were told so. The truth is [...]]]></description>
			<content:encoded><![CDATA[<p> Some people think the power of OO design is that the classes represent real-life concepts that are easier for a human to understand.  Others think that its power comes from code reuse.  Still other just accept OO as the paradigm that they are supposed to use, simply because they were told so.</p>
<p>The truth is that using any of those approaches to design may well leave you with a brittle, unmanageable, ugly mess.  Personally, I strive for the &#8220;real-life concepts&#8221; as one top-level goal.  The other top level goal is decoupling.  Transcending all goals, of course, is creating a &#8220;correct&#8221; program.  Not necessarily &#8220;correct&#8221; in the academic sense. I don&#8217;t verify every algorithm I use, and I don&#8217;t necessarily determine valid pre/post conditions.  I mean correct in as much as, it works for what I need it to work for.</p>
<p>For small programs, this is pretty easy. When you get to larger systems, this becomes a slightly different problem to solve.   In the days of goto, spaghetti code arose due to poor organization and ad hoc control transfer.  Structured programming helped some by organizing the control codes into a set of well-defined idioms.  Object oriented programming helped further by organizing responsibility into encapsulated modules.  All of these paradigms had something in common; you could write brittle code or malleable code in any one of them.  Granted, writing flexible code has gotten easier with Object Oriented programming, but only if you know what makes code brittle.</p>
<p>Over dependence of one section of code on another section of code.  In software engineering, we call this coupling.  If the behavior of A is dependent on the behavior of B, then A is dependent on B.  Changing the behavior of B could change the behavior of A.  This isn&#8217;t always a bad thing, but if A and B are written by different people (or the same person at different times) with different goals, it could be catastrophic.  It isn&#8217;t always feasible to decouple two classes, or two methods, or even two lines of code, but if you can do it easily, consider what might be gained by that.</p>
<p>One syndrome I&#8217;ve noticed is that with any concept, some people take it to the extreme. For those readers who stopped at the above paragraph and decided I was right, and everything should be as decoupled as possible, you might see a design that I would call disintegrated.  It is possible to create code that is so decoupled as to be impossible to figure out how one thing affects another, even though the overall system is design for A to affect B.  Don&#8217;t do this <img src='http://virtualinfinity.net/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>One approach to decoupling two classes is to have them communicate through an event system.  This will couple them both to the event system, but not to eachother.  This approach allows you to replace one of the pair without changing the other side at all.  This makes a lot of sense for GUI applications, for example, where user interactions with the component (such as a button) generates an event that can be handled very differently, depending on the needs of the program.  Most object oriented languages, and Java in particular, already has a useful mechanism for invoking behavior on other objects. Its called method invocation, the act of making a method call.  Event systems are useful for decoupling the method call from the class that needs to know about the call, its not so useful as a replacement for normal method invocation.</p>
<p>There are plenty of other ways to decouple you code (often through use of patterns), but I won&#8217;t get into them here. <a href="http://www.google.com/" title="Google is your friend">GIYF</a></p>
<p>Software design is about making difficult choices.  If you didn&#8217;t have to make choices, then it would be easy to create a simple program that can design software.  Your job as an engineer is to decide what should be decoupled from what.  Decoupling can be a great tool to create a reusable component, but not everything should be designed to be reusable.  If you&#8217;ve written something that was coupled, but needs to be made reusable&#8230; Well, thats what refactoring is for.  Decoupling two classes that only communicate with each other can actually add complexity for that use case, so unless you strongly believe that at least one of the two classes will be useful in other situations, it is a waste of cognitive power to separate them.</p>
<p>My goal for production-quality software design? Create the simplest design that meets all my requirements, but is flexible enough to adapt to future requirements.</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualinfinity.net/wordpress/program-design/2007/12/03/the-art-of-decoupling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Primitive Obsession II: (Im)mutability and Redefining Primitive</title>
		<link>http://virtualinfinity.net/wordpress/program-design/2007/11/04/primitive-obsession-2/</link>
		<comments>http://virtualinfinity.net/wordpress/program-design/2007/11/04/primitive-obsession-2/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 06:01:54 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Program Design]]></category>
		<category><![CDATA[abstraction]]></category>
		<category><![CDATA[decoupling]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[heading]]></category>
		<category><![CDATA[immutable]]></category>
		<category><![CDATA[mutable]]></category>
		<category><![CDATA[primitive]]></category>
		<category><![CDATA[robots]]></category>
		<category><![CDATA[simulation]]></category>

		<guid isPermaLink="false">http://virtualinfinity.net/wordpress/program-design/2007/11/04/primitive-obsession-2/</guid>
		<description><![CDATA[Last week I discussed some of the techniques for and benefits of not using simple &#8220;Primitive&#8221; values to represent your data. This article is all about taking that concept to the next level. Let&#8217;s say that I have a value that represents an angle. I could use a double to represent the radians, or I [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I discussed some of the techniques for and benefits of not using simple &#8220;Primitive&#8221; values to represent your data.  This article is all about taking that concept to the next level.</p>
<p>Let&#8217;s say that I have a value that represents an angle.  I could use a double to represent the radians, or I could create a class called Angle, which internally might use a double to represent radians.  If you are trying to avoid primitive obsession, you would use the latter.  Now you have value objects of type Angle which can be used in meaningful ways.  So, we&#8217;re done, right?  I say no.</p>
<p>Angle is now its own form of primitive. Just as an Integer object is an abstraction of a numeric value in a specific set of reals, an Angle instance is an abstraction of a geometric/trigonometric angle.  This means that it can be the building block for other more specific types.  For instance, a 2 dimensional vector can be represented in &#8220;polar form&#8221; as an Angle and a Magnitude.  In a physical simulation, a Magnitude is often a Distance, so we&#8217;ll assume that case for this article.</p>
<p>So, we can create a Vector interface (not to be confused with the java.util.Vector class).  We can then create a PolarVectorImpl class which uses Angle and Distance.  We can even create a CartesianVectorImpl which uses two Distance objects to represent the vector.  Whats more, is these can both be used by anything that expects a Vector, with no extra work in the client code.  We can easily create a rotate(Angle) method, or any other useful methods.</p>
<p>Another important and related concept that we haven&#8217;t touched on is mutability.  If an object is mutable, that means that the apparent state of the object can change over the lifetime of the object.  If an object is immutable, the apparent state of the object will appear the same throughout the lifetime of the object.   This means that any invocation of one method on that object will always have the same outcome as any other on that same method.  Also, any object that is returned from those methods must either be immutable themselves, or be distinct instances.  Why is this important?  Immutable objects have some benefits.</p>
<ul>
<li>Immutable objects are inherently thread safe.</li>
<li>Immutable objects are easy to reason about.</li>
<li>Immutable objects are easier to debug.</li>
<li>Immutable objects can be passed around freely without defensive copying.</li>
</ul>
<p>On the down side, immutability makes a pretty boring universe.  If you&#8217;re object is expected to do different things depending on what has happened to it in the past, that object <strong>must</strong> be mutable. It must have state.</p>
<p>What does this have to do with primitive values?  Its common to create immutable value objects.  If we design the Angle class to be immutable, then we can safely say that one instance represents exactly one angle throughout its lifetime.  All of our Angle objects are value objects.   They are utility objects and reusable in many projects.  On the other hand, if we&#8217;re doing a simulation of sorts, it might be useful to have a mutable angle, something that we can adjust over time.  Lets call this class Heading. What&#8217;s in a Heading? An Angle, of course.  Now here&#8217;s where things get interesting&#8230;</p>
<p>Since an Angle is a measurable thing, its easy to compare two values for equality.  For Angles specifically, they are equal if their values represent the same geometric angle.  Once equality is established, those objects are equal for ever.  Not so with Heading.  A Heading may represent the same angle at one moment in time, but at another moment they represent very different angles.  For this type of object, equality only makes sense for the identity.  A Heading instance is its own object, and can be queried/manipulated by many other objects/methods within the project.</p>
<p>The benefit of this design, is a manipulator/querier need not know who &#8220;owns&#8221; the Heading instance.  A Robot might have a Heading, and a SteeringServo might manipulate that Heading.  You can create the Robot and the SteeringServo objects independently of each other.  The SteeringServo doesn&#8217;t even need to know its the Heading of a Robot.  Once the Robot and SteeringServo both have the same Heading instance, they become connected without being coupled.  This is huge goal for Object Oriented designers/programmers.  The correct functioning of a SteeringServo isn&#8217;t dependent on the correct functioning of a Robot, or even of a Heading, only on itself.  Similarly, a Robot&#8217;s correct functioning isn&#8217;t dependent on the correct functioning of the SteeringServo.  The program as a whole may not work if there is a bug, but it easier to look at one class and ask yourself &#8220;Is there anything wrong with this code,&#8221; than it is to ask the same question about the whole project.</p>
<p>If you think all of this abstraction is unnecessary or unhelpful, think about all the layers beneath our Heading class. Lets have some fun and break it down into its most primitive parts.</p>
<ul>
<li>Heading instance is an identity value containing an Angle and representing a direction at a point in time.</li>
<li>An Angle is an equal-comparable value containing a double and representing a direction.</li>
<li>A double is a equal-comparable and order-comparable value containing an ordered set of bits and representing a real number.</li>
<li>A bit is an equal-comparable value containing a memory cell representing true or false.</li>
<li>A memory cell is often times a capacitor that is either charged or uncharged</li>
</ul>
<p>If you had to think about the implementation details of a bit every time you used a double, it would make the mental weight of programming so immense that no useful programs could be written.  Heading can now be used very easily without adding the mental weight of how its implemented.  SteeringServo can be implemented without the mental weight of what it is steering.  Overall, the practice of this kind of decoupling will make your program easier for the most important source-code interpreter. You.</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualinfinity.net/wordpress/program-design/2007/11/04/primitive-obsession-2/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Avoiding Primitive Obsession</title>
		<link>http://virtualinfinity.net/wordpress/program-design/2007/10/28/primitive-obsession/</link>
		<comments>http://virtualinfinity.net/wordpress/program-design/2007/10/28/primitive-obsession/#comments</comments>
		<pubDate>Sun, 28 Oct 2007 19:22:19 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Program Design]]></category>
		<category><![CDATA[distance]]></category>
		<category><![CDATA[duration]]></category>
		<category><![CDATA[measurements]]></category>
		<category><![CDATA[primitive]]></category>
		<category><![CDATA[primitive obsession]]></category>
		<category><![CDATA[smart values.]]></category>
		<category><![CDATA[units]]></category>

		<guid isPermaLink="false">http://virtualinfinity.net/wordpress/program-design/2007/10/28/primitive-obsession/</guid>
		<description><![CDATA[Particularly (but not just) programmers who have a background in C tend to think of simple data as primitive data. Measurements are one of the simplest types of data, so why not do something like this: public class Bob { double distance; double duration; double weight; /* ... rest of code which handles calculation based [...]]]></description>
			<content:encoded><![CDATA[<p>Particularly (but not just) programmers who have a background in C tend to think of simple data as primitive data.  Measurements are one of the simplest types of data, so why not do something like this:</p>
<pre>public class Bob {
  double distance;
  double duration;
  double weight;
  /* ... rest of code which handles calculation based on distance,
          duration, and volume, based on some predefined units for each. */
}</pre>
<p>While there isn&#8217;t anything broken about this code, it needlessly couples the algorithms used in Bob with the units used to express distance, duration, and weight.  A more robust design would give each of these there own types, which could be unit-independent.   We&#8217;ll deal with just Distance.  I&#8217;ve decided to implement the Distance class use meters as its underlying representation, but this fact is hidden from all clients of the class.  Furthermore, I&#8217;ve tried hide that fact from as many internal methods as possible.</p>
<pre>public final class Distance {
    private final double meters;

    private  Distance(double meters) {
        this.meters = meters;
    }

    public double getMeters() {
        return meters;
    }

    public static Distance fromMeters(double meters) {
        return new Distance(meters);
    }

    public Distance times(double scalar) {
        return fromMeters(getMeters()*scalar);
    }

    public Area times(Distance distance) {
        return Area.fromSquareMeters(getMeters() * distance.getMeters());
    }

    public Distance plus(Distance distance) {
        return fromMeters(getMeters() + distance.getMeters());
    }
}</pre>
<p>So, what do we have here? Distance now has methods that give you more meaningful operations.  A Distance multiplied by another Distance is specifically an Area, but a Distances multiplied by a scalar (simple number), is just a scaled Distance.  You can&#8217;t add an arbitrary scalar to Distance on accident.</p>
<p>If we were using simple <code>double distance</code> and used the convention that distances was measured in meters, we might see code like <code>distance+=3; // add three meters</code> Unfortunately, if we switch to a different metric, we just broke that line.  Using the non-primitive Distance, the same line would be distance = Distance.plus(Distance.fromMeters(3));  Now, no one is constrained to use meters. We could easily add fromInches, getInches, fromYards, getMicrons, etc&#8230; We could also decide change the internal representation of Distance to use BobUnits (3.14 Bob Units is one Meter ), and no client code need be touched!</p>
<p>Another useful example are measurements which usually have other associated values with them.  For example, Angles.  Angles can be measured in Degrees, Radians, and many other units.  They also have associated sine, cosine, tangent.  So, lets take a look at an Angle class:</p>
<pre>public final class Angle {
    private final double radians;

    private Angle(double radians) {
        this.radians = radians;
    }

    public double cosine() {
        return Math.cos(getRadians());
    }

    public double sine() {
        return Math.sin(getRadians());
    }

    public static Angle fromCartesian(Distance x, Distance y) {
        return fromRadians(Math.atan2(y.getMeters(), x.getMeters()));
    }

    public static Angle fromRadians(double radians) {
        return new Angle(radians);
    }

    public Angle plus(Angle angle) {
        return fromRadians(getRadians() + angle.getRadians());
    }

    public double getRadians() {
        return radians;
    }
}</pre>
<p>Again, we arbitrarily choose radians as the implementations unit, and again we don&#8217;t expose this to the client, and we don&#8217;t rely on it internally unless we have to.  We have an Angle plus an Angle is an Angle.  We also have a way to get an angle from a Cartesian coordinate.<br />
What&#8217;s more, we have sine() and cosine().  That&#8217;s the big deal with Angle! Now our clients don&#8217;t need to use ugliness such as &#8220;Math.cos(angle * degreeToRadians)&#8221;.  If they have an Angle, they can get the sin, cos, degrees, radians, etc&#8230; Without having to know the details of the underlying units.</p>
<p>Now, any of these can be turned into interfaces or abstract classes, and then you could have different implementations based on the system needs.  For instance, if you&#8217;re dealing with subatomic measurements, meters doesn&#8217;t make sense for distances, and seconds doesn&#8217;t make sense for durations. You could have a MicronDistanceImpl implementation of Distance, and NanosecondDurationImpl implementation of Duration.  Similarly for a cosmic simulation, you could have light-years for Distance and millennia for Duration.</p>
<p>Oh, almost forgot.  This also gives you the ability to have nice toString() representations.  I haven&#8217;t added those to the above classes, but I could imagine the toString printing &#8220;12.0 meters&#8221; and &#8220;32.6 degrees&#8221;.  This will help when presenting these values to a user as well.</p>
<p>This kind of abstraction is what makes good design.  Next time you declare something as a primitive (or a dumb primitive wrapper such as Double, or Integer), think about what type units you might assign to it.  You&#8217;ll find that your classes become simpler as well, since they don&#8217;t get bogged down in the formulas needed to convert between units.  It also gives you much more expressive power.  Think of a Speed class which has Distance and Duration fields.  Maybe even a method on Distance <code>public Speed divide(Duration duration);</code></p>
]]></content:encoded>
			<wfw:commentRss>http://virtualinfinity.net/wordpress/program-design/2007/10/28/primitive-obsession/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using enums as a flyweight pattern.</title>
		<link>http://virtualinfinity.net/wordpress/program-design/2007/10/22/using-enums-as-a-flyweight-pattern/</link>
		<comments>http://virtualinfinity.net/wordpress/program-design/2007/10/22/using-enums-as-a-flyweight-pattern/#comments</comments>
		<pubDate>Mon, 22 Oct 2007 18:28:32 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Program Design]]></category>
		<category><![CDATA[barnyard]]></category>
		<category><![CDATA[enums]]></category>
		<category><![CDATA[flyweight]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[polymorphism]]></category>
		<category><![CDATA[strategy]]></category>

		<guid isPermaLink="false">http://virtualinfinity.net/wordpress/program-design/2007/10/22/using-enums-as-a-flyweight-pattern/</guid>
		<description><![CDATA[When the Java people introduced enums, they went out of their way to support the switch statement with enums. Good OO design tends to avoid switches and instead use polymorphism to &#8220;decide&#8221; on behavior. While you can switch on enums, you also can add behavior to enums. As a matter of fact, this is useful [...]]]></description>
			<content:encoded><![CDATA[<p>When the Java people introduced enums, they went out of their way to support the switch statement with enums.  Good OO design tends to avoid switches and instead use polymorphism to &#8220;decide&#8221; on behavior.  While you <em>can</em> switch on enums, you also can add behavior to enums.   As a matter of fact, this is useful for the flyweight pattern.</p>
<p>First, for those who don&#8217;t know, a Flyweight is a stateless object that represents some behavior for a set of other objects.  For example, if you had to have an &#8216;e&#8217; Glyph&#8221;object for every letter &#8216;e&#8217; in this article, you&#8217;d have a lot of instances of the e glyph object.  Using a flyweight, you have one instance of the &#8216;e&#8217; Glyph, and whenever you need to evoke the behavior, you pass in the &#8220;state&#8221; (eg. the position on the screen) to the appropriate method.</p>
<p>For small sets of Flyweights, where the difference between any two instances is mostly behaviorally, enums are very useful.  They wouldn&#8217;t be so useful for the &#8216;e&#8217; Glyph example, since we&#8217;d have to write an enum with every character we wished to support. Glyphs also mostly differs in the shape, which can be broken down into data rather than behavior.</p>
<p>So, for our example, we&#8217;ll be using a Flyweight to mimic animals.  Lets start out with our different types of animals.</p>
<pre>public enum AnimalType {
    Cow,
    Chicken,
    Pig,
    Lion
}</pre>
<p>Now, if we wanted to have an Animal class.  Lets assume that we have an &#8220;World&#8221; class that contains information about our animal&#8217;s world. Including food sources and animal position, etc&#8230;</p>
<pre>public final class Animal {
   private final AnimalType type;
   private final World world = World.getWorld();
   private int hungerLevel;
   public Animal(AnimalType type) {
      this.type = type;
   }
}</pre>
<p>Now, objects aren&#8217;t generally useful unless they have behavior.  We&#8217;re going to add simple delegation from the Animal class to its AnimalType instance.</p>
<pre>public final class Animal {
   private final AnimalType type;
   private final World world = World.getWorld();
   private int hungerLevel;
   private int restLevel;
   public Animal(AnimalType type) {
      this.type = type;
   }

   public void eatFood() { type.eatFood(this);}

   public void sleep() {
     type.sleep(this);
   }

   public World world() { return world; }
}

public enum AnimalType {
    Cow {
        public void eatFood(Animal animal) {
            animal.world().findGrass().consumeBy(animal);
        }
        public void sleep(Animal animal) {
            animal.world().findBarn().sleptInBy(animal);
        }
    },
    Chicken{
        public void eatFood(Animal animal) {
            animal.world().findCorn().consumeBy(animal);
        }
        public void sleep(Animal animal) {
            animal.world().findCoop().sleptInBy(animal);
        }
    },
    Pig{
        public void eatFood(Animal animal) {
            animal.world().findTrough().getContents().consumeBy(animal);
        }
        public void sleep(Animal animal) {
            animal.world().findBarn().sleptInBy(animal);
        }
    },
    Lion {
        public void eatFood(Animal animal) {
            animal.world().findPrey().consumeBy(animal);
        }
        public void sleep(Animal animal) {
            animal.world().findSavana().sleptInBy(animal);
        }
    },
;
    public abstract void eatFood(Animal animal);
    public abstract void sleep(Animal animal);
}</pre>
<p>So, as you can see, each animal has its own behavior. This particular flyweight implements the Strategy pattern for both eatFood() and sleep().</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualinfinity.net/wordpress/program-design/2007/10/22/using-enums-as-a-flyweight-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Food for thought: What does &#8220;the business layer&#8221; really mean?</title>
		<link>http://virtualinfinity.net/wordpress/program-design/2007/10/02/food-for-thought-what-does-the-business-layer-really-mean/</link>
		<comments>http://virtualinfinity.net/wordpress/program-design/2007/10/02/food-for-thought-what-does-the-business-layer-really-mean/#comments</comments>
		<pubDate>Tue, 02 Oct 2007 20:22:44 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Program Design]]></category>
		<category><![CDATA[abstraction]]></category>
		<category><![CDATA[business layer]]></category>
		<category><![CDATA[generalization.]]></category>

		<guid isPermaLink="false">http://virtualinfinity.net/wordpress/2007/10/02/food-for-thought-what-does-the-business-layer-really-mean/</guid>
		<description><![CDATA[The other day I read a blog post titled The Mythical Business Layer. This blog talks about the dangers of trying to separate the &#8220;Business Logic&#8221; from all the different layers of a system. One of the more important points that this article makes is: There is absolutely nothing wrong with having a multi-layered application. [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I read a blog post titled <a href="http://worsethanfailure.com/Articles/The-Mythical-Business-Layer.aspx">The Mythical Business Layer</a>.  This blog talks about the dangers of trying to separate the &#8220;Business Logic&#8221; from all the different layers of a system.</p>
<p>One of the more important points that this article makes is:</p>
<blockquote><p>There is absolutely nothing wrong with having a multi-layered application. In many cases, anything but that would be a bad design. It’s absolutely critical, however, to not think of these layers as persistence, business, and presentation. Database, processing, and user interface are much more appropriate terms.</p></blockquote>
<p>I think that all of us can get stuck on the trying to move some logic into a place where it doesn&#8217;t really belong. If moving the logic into another location causes your system to be more complicated, then its probably the wrong place to move it.</p>
]]></content:encoded>
			<wfw:commentRss>http://virtualinfinity.net/wordpress/program-design/2007/10/02/food-for-thought-what-does-the-business-layer-really-mean/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
