Click here to Skip to main content
15,884,010 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Morning,

Only just signed up to this site but I have read a lot of articles previously and found it really useful, so thank you for that!

I am currently studying towards my final year of a Computer Science degree, and working on my final project and dissertation. I will be using ASP.NET Web Forms and C# to create a 3-Layer project - I can't really call it 3-Tier as it will most likely never be hosted on anything other than my local PC for testing as it is for uni purposes only.

My main question is this:

From my understanding, the idea of 3-Layer is that the BLL references the DAL, and the UI references the BLL to create complete separation of concerns. However I have made a small mock up project following a few tutorials so get the hang of 3-Layer, and most basic tutorials still require a reference between the UI and BLL.

For example in the project I have created, which is a very basic Products and Categories type e-commerce system, I have created the Product and ProductDAL classes in the DAL, then the ProductBLL class in the BLL. With this setup, of only using one database table (forget categories for now), the BLL seems to only serve as a sort of interface between the UI and DAL, the methods are exactly the same as those in the DAL and only call the DAL version.

The problem is that to access the DAL via the BLL, I have to pass in a Product object to the BLL method arguments, which means creating a Product object in the UI first, which means referencing the DAL from the UI. Is this the correct way of doing things?

I can get around simple cases like this by creating a method in the BLL that takes the appropriate fields, e.g. strings and ints to create the Product Object and returns it to the AddProduct method. However when it comes to binding different product attributes to labels in the UI, I still need access to the Product object.

So essentially, do I need to make a load of methods in the BLL to access properties of the Product Object? If not, what kind of methods would actually go there, can you give me any examples of methods that may go in the BLL in this kind of Product scenario?

Thanks in advance, and apologies if this has been asked before - I did read through a lot of posts about 3-Layer architecture but most are very basic and only access one table.

Cheers,
Stu.
Posted

The approach I follow is I have 4 layers: UI, BLL, Objects and DAL. UI layer references BLL and Objects layers, BLL references Objects and DAL layers and DAL references Objects layer.

Now, this Objects layer is where you create classes that represent objects like Product, Customer etc and these classes would just hold the data for the individual member properties. Using this 4-tier approach, you can easily bind Objects in your UI because it now references Objects (think of this as a common layer that can be used by all the layers).

Everything else remains as is in terms of method call propagation from the UI all the way down to the DAL. Ofcourse even this architecture can be improved and refactored quite a bit like moving all the code that directly handles db stuff i.e. queries to a separate dll and then provide a conversion mechanism between data access objects and your business objects in the Objects layer. Hope this helps.
 
Share this answer
 
Comments
stuuz 30-Oct-12 9:43am    
Thank you so much for the reply, it has helped a great deal and I am now running a 4 layer application where the DAL, BLL and Presentation all reference a common Entities layer.

The only code I really have in the presentation layer now is creating instances of BLL / Entity objects, binding data controls to these object methods, and pulling data from TextBox's / DropDownList's etc to fill the attributes of an Entity before passing it off to the BLL method.

Is this the right idea, and an acceptable amount of code to appear in the presentation layer?

Cheers,
Stu.
I.explore.code 30-Oct-12 9:56am    
within the tenets of n-tier architecture, yes, its an acceptable amount of code to be written in the presentation layer infact, this is the minimum you will need. If you use MVC style, things would be a lot different. Glad I could help mate!
Hi bro,

As you are new to .Net you have asked good question. Here is answer for your question step by step:

Step 1: Create a new class library project for your Data Access Layer.

Stet 2 :
Add a new class library project to your solution and name it like ModalLayer. Now put your modal class like 'ProductInfo' it will just contain Properties nothing else ok. e.g.

C#
public class ProductInfo
 {
   //Gets or sets the product id
   public int ProductId {get; set;}

   //Gets or sets the product name
   public string ProductName {get; set;}

 }


Now you have created class in ModalLayer which contains ProductInfo class, now you just need to put a reference to Data Access Layer Project so that you can have access to ProductInfo class in Data Access Layer.

Step 3:
Add one more class library project to your Solution named like ProductBLL and again put the reference of ModalLayer project to ProductBLL project which can access your ProductInfo class.

Step 4: Now at last create your UI project like ASP.NET or whatever you need like WPF an others. And again put reference of ModalLayer in this project and you can also access ProductInfo class here.

But don't forgot to give reference of DLL to BLL and BLL to UI as well. Now you can pass your data easily from one layer to other.

Thanks
 
Share this answer
 
Comments
stuuz 30-Oct-12 9:44am    
Thank you for this detailed response, it has helped a lot and confirmed that I am now doing the right thing!
Brajabas 1-Nov-12 10:51am    
Dear Satyendra Sir, I need some guidance related to study materials/ebooks/books so that I can follow the layer based approach in developing projects
Satyendra Kumar(Analyst Programmer) 1-Nov-12 17:22pm    
Hi you can download pdf available on microsoft's site named MICROSOFT
APPLICATION ARCHITECTURE GUIDE. From this link http://apparchguide.codeplex.com/
but this is in detailed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900