Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1322
  • Last Modified:

How to construct DAL & BLL?!?!?

OK, I have had it!

How do you design DAL & BLL?!??!?? For love sakes!

Do you have methods like Open(), Close(), ExecuteScalar(string spName), ExecuteReader(string spName, DbParameter[] parameters), CreateParameter() etc. !??!?!?!?!??!?!?!?!?!!?!?!!??!?!?!?!?!?!?!?

Or do you have your entire logic in the DAL and just call the methods in the DAL class from the BLL class... with the exact same name as they appear in the DAL... just aliasing them... !?!!??!?!?

Do you have a class per entity???

How do you make them generic???

Do you have methods like GetEmpleyeeByID(string empID) in your BLL!?????!???

Or do you have methods like GetEntities().. ?!???

Do you open the connection directly for each method from the DAL...?? Or do you reveal the Open(), Close().. for the BLL to use!?

Do you use Try...Catch...Finally statements right on the DAL methods?? Or do you use them in the BLL??? Or do you even use them in the PL(UI)???

Some say this... some say this... and some say "use the wizards..." - I do not want use the wizards!!


So how the **** do you write DAL & BLL properly...
which can later on be used for other projects!?
0
zooz111
Asked:
zooz111
  • 2
  • 2
2 Solutions
 
TMarkham1Commented:
You're going to love this answer...

It depends.

The reason "some say this"... and "some say that" is because this area isn't really a "one size fits all" kind of entity. I've worked for many companies who each had different requirements regarding data access layer and business logic layer design. Incidentally, none of these companies got it "perfect" in my honest opinion... but they all worked well enough.

One methodology I personally like is this one from Paul D. Sheriff and Associates on the Fundamentals of N-Tier Architecture, which includes the data access layer and business logic layers. This isn't the method I employed at any of my jobs however... I just thought it looked like a good way of doing it. This is an e-book and it costs about $20.

http://www.pdsa.com/Products/ProductDetail.aspx?prod=51

0
 
zooz111Author Commented:
Thank you for your answer!

I'll take a look at that book.
0
 
DarrenDCommented:
Hi,

I've tried to answer your question as best I can. But I think that you should decide what type of architecture you wish to use...

What are you going for? These are just three that you could use...
Client -> BLL/DAL -> Database
Client -> BLL -> DAL -> Database
Client -> BLL -> Entities -> DAL -> Database

How do you design DAL & BLL?!??!?? For love sakes!
You can put the DAL and BLL into the same DLL or you can have the DAL as a seperate DLL only performing the actual database operations no mater what table you are wishing to update. Then you can have DataEntities which are classes that represent the actual tables. These contain the CRUD operations and use the DAL to simply exectute the SQL SP. The BLL can use one or many of the DataEntities in order to perform some operation and return a either a new class that is a mixture of the other Entities or just an Entity.

Do you have methods like Open(), Close(), ExecuteScalar(string spName), ExecuteReader(string spName, DbParameter[] parameters), CreateParameter() etc. !??!?!?!?!??!?!?!?!?!!?!?!!??!?!?!?!?!?!?!? Yes. You can create an interface for a DAL and place the method names mentioned above it the interface as methods. Then simply implement the interface for whatever database you are connecting to.

Or do you have your entire logic in the DAL and just call the methods in the DAL class from the BLL class... with the exact same name as they appear in the DAL... just aliasing them... !?!!??!?!? Not sure what you mean here.

Do you have a class per entity??? Entity class per table? Yes

How do you make them generic??? Don't know what you mean. Don't think you can make the entity class generic

Do you have methods like GetEmpleyeeByID(string empID) in your BLL!?????!??? Yes, I would CALL GetEmpleyeeByID(string empID) from the BLL but the actual method would be in the EmployeeEntity class which is a copy of the structure of the database table Employee.

Or do you have methods like GetEntities().. ?!??? In the Entity classes I would have GetEntities() and GetEtities(EntityId) etc... and then let the business layer validate and perform operations.

Do you open the connection directly for each method from the DAL...?? Or do you reveal the Open(), Close().. for the BLL to use!?
Only to BLL. Only create the DAL class when you need to read or write to the database and then close it immediately.

Do you use Try...Catch...Finally statements right on the DAL methods?? Or do you use them in the BLL??? Or do you even use them in the PL(UI)??? Yes, in order to catch any Server/Database specific errors it is a good idea to have try catch blocks around all methods in all layers and catch them in order to display a useful message to the user.

Hope this helps,

Darren
0
 
DarrenDCommented:
Also,

You should decide if you want to code everything yourself as you could use Microsoft .NET application blocks for Data Access.

http://www.cyberforge.com/weblog/aniltj/articles/217.aspx
0
 
zooz111Author Commented:
Alright, thank you very much, DarrenD, for your answers.

>> "Or do you have your entire logic in the DAL and just call the methods in the DAL class from the BLL class... with the exact same name as they appear in the DAL... just aliasing them... !?!!??!?!? Not sure what you mean here."

What I meant was...
I've seen people using their BLL as a reference-only for the DAL (The name of the method appears the SAME as in the BLL, DAL, and the same name for the StoredProcedure...).
The only thing in their BLL is a reference to the same thing in the DAL.. and in the DAL sits the whole logic of the action.
And even sometimes people use "SqlHelper" classes... to do the actions... like ExecuteScalar for instance....
Then what good is their BLL then!? Right?
They say that their BLL is used for information checking.. data converting.. (before or after passing to the DAL....) which I hardly seen them do... It's mostly just a reference to the DAL...


A-n-y-w-a-y-s, here's my BLL & DAL if you'd like to take a look...
And maybe tell me what I'm doing wrong or right....
BLL.txt
DAL.txt
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now