locked
Function implementation in 3-tier architecture RRS feed

  • Question

  • User-513790065 posted

    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?


    Thanks 


    Wednesday, April 28, 2010 7:07 AM

Answers

  • User624841477 posted

    Hi,

     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.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 28, 2010 7:33 AM
  • User-952121411 posted

    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()
            MyBL.MyBLMethod(MyStringVal1, MyStringVal2)
    
            'At this point the values will be as follows:
            'MyStringVal1 = "Hello"
            'MyStringVal2 = "Test"
    
        End Sub
    
    End Class
    
    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()
            MyDal.MyDALMethod(StringVal1, StringVal2)
    
        End Sub
    
    End Class
    
    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"
    
        End Sub
    
    End Class


    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! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 28, 2010 3:53 PM

All replies

  • User624841477 posted

    Hi,

     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.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 28, 2010 7:33 AM
  • User-952121411 posted

    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()
            MyBL.MyBLMethod(MyStringVal1, MyStringVal2)
    
            'At this point the values will be as follows:
            'MyStringVal1 = "Hello"
            'MyStringVal2 = "Test"
    
        End Sub
    
    End Class
    
    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()
            MyDal.MyDALMethod(StringVal1, StringVal2)
    
        End Sub
    
    End Class
    
    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"
    
        End Sub
    
    End Class


    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! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 28, 2010 3:53 PM