Tuesday, December 21, 2010

How to implement the Business Layer


Summary: I explained the difference between the presentation, business and data layer. In this instalment, I will explain how to implement the business layer and the objects you will need to build and how they interact.

Introduction:
I started writing this series in response to what I thought were overcomplicated explanations of a fairly simple subject. I have also noticed that there seems to be a 50-50 split in the newsgroups and forums about how n-tier should be implemented. Should it use ADO.NET as a basis, or should it be implemented in an object-centric way? Each method has its advantages. If you use ADO.NET you get all the pre-implemented advantages the .NET development teams have provided. However, you can't encapsulate functionality into a DataSet or DataTable object. On the other hand, an object-centric approach means that you have to re-implement all the fantastic ADO.NET functionality. In an attempt to bridge the gap, the method I use is a mixture of both approaches. By using ADO.NET in an object-centric way, we could gain the benefits of both.
In the first part, I set the scene by showing the evolutionary process which brought us to the n-tier stage. In this article, I will explain how to implement a simple but non-trivial part of the Customer/Order part of the Northwind database and we will explore what the best way is to implement the Business layer.  In the following instalments, we will look at the data layer and the presentation layer. Finally we'll look at moving our blocks of code onto different physical machines using .NET Remoting and XML Web services. As you will see, many technologies and prerequisites are required in order to understand how this works, including interfaces and ADO.NET.
Although this article is an introduction to .NET architecture, it assumes that you have knowledge of .NET mechanics and the use of OO concepts such as interfaces. If there is enough demand, I'll supplement this article with a series on how these concepts are implemented in .NET. So with this proviso, let's have a look at how to implement an n-tier architecture you can apply to your most complex projects.
Please note that this article does not contain attached code. Full code will be supplied in the 3rd instalment as source code is meaningless without a data layer.