Last post Apr 28, 2010 03:53 PM by atconway
Apr 28, 2010 07:07 AM|himchr|LINK
I have implemented the 3-tier architecture project; DAL, BAL, and presentation layer are three layers in it. I am going to implement the following scenario:
Presentation layer calls to a function in the BAL layer which returns 2 string variable, and in turn this function from BAL layer calls to a DAL layer function which also returns 2 string variable.
How can I implement the above scenario?
Apr 28, 2010 07:33 AM|sunilyadav165|LINK
You can do it in simple ways as follows:
1.Create asp.net project which will act as presentation layer.
2.Create two class libraries whic will acts as BAL and DAL.
Once you have created all the above and written your Business logic and Data access logic, you can add reference of DAL class library to BAL class library and finally add BAL reference to asp.net application to get it work.
hope it helps.
Apr 28, 2010 03:53 PM|atconway|LINK
Presentation layer calls to a function in the BAL layer which returns 2 string variable
I am going to provide a code example that is very specific to answering your question directly. I honestly think populating properties on objects to be returned or generated would be a better method, but you asked how calling through the
layers could return (2) string values. Because a 'Function' in .NET can only have 1 return value, you need to define the parameters 'ByRef' (out parameters in C#), have 1 return value, and 1 ByRef parameter, or not return values directly
and use objects instead to have a more OOP approach where values belong to classes that define behavior and encapsulate logic. But again, I wanted to show you precisely how what you asked could be done, so take a look at this basic example:
Public Class UserInterface
Public Sub MyUIMethod()
'Define (2) values that will be defined by calling the BL
Dim MyStringVal1 As String = String.Empty
Dim MyStringVal2 As String = String.Empty
'Call the BL to get back values; notice values are passed in 'ByRef' and are defined internally
Dim MyBL As New BusniessLogic()
'At this point the values will be as follows:
'MyStringVal1 = "Hello"
'MyStringVal2 = "Test"
Public Class BusniessLogic
Public Sub MyBLMethod(ByRef StringVal1 As String, ByRef StringVal2 As String)
'Call the DAL method that defines ByRef (2) string values; set the method ByRef parameters for caller as well
Dim MyDal As New DataAccessLayer()
Public Class DataAccessLayer
Public Sub MyDALMethod(ByRef StringVal1 As String, ByRef StringVal2 As String)
'Define the (2) reference values on the method
StringVal1 = "Hello"
StringVal2 = "Test"
There is obviously a lot of real world implementation details left out of this example between the layers, but I wanted to display how the (2) strings you need returned from a separate layer could be achieved.
Hope this helps!