Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Friday, November 24, 2006

Domain Rules in .NET


This article shows how you can solve a domain problem, with several different solutions. In the graph above you can see the six solution names. I have explored each solution using exactly the same problem.

I've always said that there is no wrong way to develop code. What do I mean by that? Well, you could solve a problem in several ways. Some solutions may be more elegant, others have better performance. But personally I prefer the solution that would make maintenance the easiest. So how do you know which solution is the best? That is exactly what I will try to answer in this article.

Software Development techniques have evolved considerably in the last two decade's. When I started programming in Visual Basic 4 we relied on procedural programming to solve our software problems. Object-Orientation was mainly academic and not widely used. Then I learned Java and my world changed considerably. Inheritance and polymorphism opened so many new possibilities. Today the rise of Dynamic languages is taking centre stage and soon we will shift to a new paradigm.


The problem domain we would like to solve is as follows:

  1. We need to represent the concept of an Investor in our application.
  2. Our Investor should know its marginal tax rate and tax liability calculated from the investor’s income.
  3. The income tax laws for the following countries should be incorporated:
    • USA.
    • Australia.
    • New Zealand.
  4. If none of these countries are specified, the object should have non-exceptional behavior.

What does non-exceptional behavior mean? The application should provide intelligent do nothing behaviors if none of the countries are specified by hiding the details from its collaborators.

Sample Image - Metrics Compared.jpg

1. Procedural Object-Orientation

Now please don't flame me about the title.

What I mean by Procedural Object-Orientation is code that is written in OO containers like classes, but any program logic captured in these object are written procedural. Code written in this manner tends to have big methods with numerous conditional constructs. Here is the class diagram of the Investor class written in the procedural manner: More

Post a Comment