CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Eric Wise

Business & .NET

Easy Assets .NET :: Part 2, Choosing a Design Pattern

Ok, now that I had defined my goal/target, it was time to start thinking about what design pattern I wanted to use.  I had a few thoughts about I wanted to achieve with the code as follows:

  1. I wanted separation between the GUI and the business logic.
  2. I only need to support SQL server databases, assuming that if someone is going to use a .NET application that they have access to either SQL Server or MSDE.  I will use stored procedures for the vast majority of queries.
  3. I wanted to use a pattern that isn't overly complex, both so that I wouldn't have to spend alot of time building complex objects, and because I do intend to release a source included version someday, and I want that source to be easy to follow.
  4. This data model and logic is not very complex, consisting mostly a simple data in/data out.  There is not alot of complex interaction going on between objects beyond a simple primary key pointer reference.

With all this in mind, I decided to use the Table Module Pattern.  The table module pattern is useful in situations where your pattern is shaping up to use the Domain Model combined with the Active Record pattern.  Here's some general info about the Table Module Pattern:

  • The data structure is very much in the center of the code.  For a table oriented data structure, this is hands down the most simple and straightforward pattern for data manipulation.  Table Module thrives on .NET recordsets/datasets.
  • The objects will basically mimic a SQL table, exposing your CRUD (create, retrieve, update, delete) and encapsulating your business logic/behavior with the data for extra simplicity.  Just about any developer should be able to follow your code easily.
  • Table Module exposes a very easy way to use inheritence by overriding the CRUD functions and adding additional properties to support special instances of objects.  (For example, an Employee my have a network login, an ITEmployee may have a second network login with higher priviliges than their normal user account.)  You can also use inhertence to expose commonly used views or other queries.
  • Complicated domain logic and polymorphism don't work very well in this pattern, if you are going to make use of these, check out the Domain Model.

So with this pattern, I have basically two classes for each table.  The first class is the single instance of the entity that a table holds (ie: employee).  The other class, denoted by it's plural name (ie: employees) is used to run queries and searches that return collections of the employee object.  I generally choose to bind my own collections to grids, dropdownlists, etc instead of using datareaders and datasets.  This is a personal preference, nothing is stopping you from using them.

My next article will show some code examples of how I set up my table module objects.



Comments

Eric Wise said:

Actually if you think about it, Access is more expensive than SQL Server... MSDE/SQL Express 2005 are free downloads.

When I do release the source included version I will probably have two versions of the installer, one without msde, and one that installs msde for them.

I'm pondering just holding off releasing the source included version until sql server express is available since it looks easier from the non-tech to learn to manage.
# September 29, 2004 1:48 AM

Eric Wise said:

Easy Assets .NET :: Part 3A, Table Module Code Samples
# November 5, 2004 10:57 AM

Dhominator said:

Did you consider DAAB 3.1 (abstract data factory)? Not much overhead (code wise) and would allow your user community to use/add other databases. Programming against the IDb* interfaces isn't really a burden.

Your thoughts?
# December 13, 2004 2:56 AM

Eric Wise said:

Dhominator- No I haven't looked at. I'll check it out though someday when I get the chance. I haven't been doing much with my home business of late due to a huge project I'm on + my wife being pregnant.

I actually have been considering selling the right to the application to a company that can give it the marketing justice it deserves.
# December 13, 2004 3:22 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors