Passing Business Object Between Dal And Bll

A Member? Please Login  
type your username and password to login
Date: October 14, 2008, 05:43 PM
249860 members and 148558 Topics
Latest Member: xlfemzy
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Passing Business Object Between Dal And Bll
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Passing Business Object Between Dal And Bll  (Read 971 views)
Smart K. (m)
Passing Business Object Between Dal And Bll
« on: November 07, 2007, 01:49 PM »

hi guys,
in the past i had to struggle to get my solution organized so that i would not have troubles of maintenance. I came across a lot of models and methods but I was not really fully satisfied. Hoever, I decided to go for separation of layers of my solution into projects namely, myweb(the site), BLL (Business Logic Layer) and DAL (Data Access Layer).

However, I ran into problem passing data between BLL and DAL because there are times i need to pass complex data and I wanted to avoid passing unreasonable no of parameters. For instance, say i want to update a student data that has 60 fields through DAL from BLL, i needed to pass the 60 parameters to DAL from BLL. I guess this is not a best practice. Note that I could not pass BLL objects to DAL as this will result in circular reference.

So, I introduced another layer to my solution called PRL (Presentation Layer). This layer forms the base layer for the BLL and DAL and contains the basic abstract classes that I would pass between DAL and BLL. As a matter of separation principle I made sure that PRL objects do not contain any methods. I make BLL objects inherit from these objects and therefor can pass BLL objects to DAL without hassles. finito.


Here are my sample codes

PRL (VB)
Public MustInherit Class Account
    Private _accountNumber As String
    Private _accountName As String
    Private _balance As Double

    Public Property AccountNumber() As String
        Get
            Return _accountNumber
        End Get
        Set(ByVal value As String)
            _accountNumber = value
        End Set
    End Property
    Public Property AccountName() As String
        Get
            Return _accountName
        End Get
        Set(ByVal value As String)
            _accountName = value
        End Set
    End Property
    Public Property Balance() As Double
        Get
            Return _balance
        End Get
        Set(ByVal value As Double)
            _balance = value
        End Set
    End Property

End Class

DAL (VB)
Public Class InsertAccount
    Public Function Update(ByVal account As Presenters.Account) As Boolean

        '//call stored procedure or something and return success or otherwise
        Return True

    End Function


End Class

BLL (C#)
public class Account :  Presenters.Account
    {
        public bool Update()
        {
            DAL.InsertAccount ia = new DAL.InsertAccount();
            return ia.Update(this);
        }
    }


SampleSite (C#)
protected void Page_Load(object sender, EventArgs e)
    {
        BLL.Account acct = new BLL.Account();
        acct.AccountName = "Magaji";
        acct.AccountNumber = "12346578";
        acct.Balance = 123311123321;

        if (acct.Update()) this.TextBox1.Text = "Updated";
        else this.TextBox1.Text = "Failed";

    }

Please, never mind about language mixing. I also use it to relay that .NET solution can contain more language.

Please enjoy.

Good luck.


* myScreen.jpg (78.38 KB, 961x441 )
 Programming Jokes  Who Knows Phone Programming?  Web Development Using ASP  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Job Talk Jobs/Vacancies (2) Career Talk Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.