Thursday, 16 August 2007

N-Tier development revisited

Discussion forums on the web are full of .Net N-tier questions, especially on approaches for achieving loosely coupled layers and lightweight data passing mechanisms. Is it ok to pass a DataSet or DataTable? Should I use Custom classes? This article by Imar Spaanjaars is one of the better ones I have seen on the topic:

http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=416

He describes the pros/cons of the different approaches. He is a fan of pulling the "data only bit" out of your business layer objects and putting them into separate "business objects" (only containing data). This aids passing of data between tiers and project referencing.

Question though - does pulling the data out of your business layer objects go against pure OO principles? "An object should consist of the data and operations allowed on that data" etc. Abstract data types (ADTs), encapsulation etc bla bla...

Also, I don't like the BO (business object) terminology as it is used, as this implies more than just data... I'd prefer something like CustomerBDO (business data object) or even CustomerEntity. You could then perhaps lose the "*Manager" suffix notation he has adopted for the business logic layer.

Regardless of these points though, I think custom classes are the correct way forward for "passing data", and datatables etc should be saved for when the types of the results are dynamic, e.g. "adhoc reporting" result sets. 

2 comments:

Anonymous said...

Hi Dave

Interesting ideas. As I said in my articles, I am always looking for ways to improve the concepts of my design.

I'll certainly keep your "Entity" references in mind for a future version / update of the article. I agree this removes the need for the *Manager suffix in the Manager classes, creating a cleaner API.

Cheers,
Imar Spaanjaars
http://imar.spaanjaars.com/

Dave Clarke said...

Thanks Imar. The structure/naming convention I'm currently adopting is:

\BusinessDataObjects\
.. Person.cs
.. Company.cs
\BusinessLayer\
.. PersonBL.cs
.. CompanyBL.cs
\DAL\
.. PersonDAL.cs
.. CompanyDAL.cs

this is working really well and feels natural when developing. I'll see how it pans out.
Cheers
Dave