How should I provide access to this custom DAL?
Posted
by Casey
on Stack Overflow
See other posts from Stack Overflow
or by Casey
Published on 2010-05-13T14:43:03Z
Indexed on
2010/05/13
14:44 UTC
Read the original article
Hit count: 444
I'm writing a custom DAL (VB.NET) for an ordering system project. I'd like to explain how it is coded now, and receive some alternate ideas to make coding against the DAL easier/more readable. The DAL is part of an n-tier (not n-layer) application, where each tier is in it's own assembly/DLL.
The DAL consists of several classes that have specific behavior. For instance, there is an Order class that is responsible for retrieving and saving orders. Most of the classes have only two methods, a "Get" and a "Save," with multiple overloads for each. These classes are marked as Friend and are only visible to the DAL (which is in it's own assembly).
In most cases, the DAL returns what I will call a "Data Object." This object is a class that contains only data and validation, and is located in a common assembly that both the BLL and DAL can read.
To provide public access to the DAL, I currently have a static (module) class that has many shared members. A simplified version looks something like this:
Public Class DAL
Private Sub New
End Sub
Public Shared Function GetOrder(OrderID as String) as OrderData
Dim OrderGetter as New OrderClass
Return OrderGetter.GetOrder(OrderID)
End Function
End Class
Friend Class OrderClass
Friend Function GetOrder(OrderID as string) as OrderData
End Function
End Class
The BLL would call for an order like this:
DAL.GetOrder("123456")
As you can imagine, this gets cumbersome very quickly. I'm mainly interested in structuring access to the DAL so that Intellisense is very intuitive. As it stands now, there are too many methods/functions in the DAL class with similar names.
One idea I had is to break down the DAL into nested classes:
Public Class DAL
Private Sub New
End Sub
Public Class Orders
Private Sub New
End Sub
Public Shared Function Get(OrderID as string) as OrderData
End Function
End Class
End Class
So the BLL would call like this:
DAL.Orders.Get("12345")
This cleans it up a bit, but it leaves a lot of classes that only have references to other classes, which I don't like for some reason.
Without resorting to passing DB specific instructions (like where clauses) from BLL to DAL, what is the best or most common practice for providing a single point of access for the DAL?
© Stack Overflow or respective owner