none
The Three Layer in Win APPlication(A BIG PROBLEM) RRS feed

  • Question

  • Hello Folks,
    If you have search for Three Layer Artichecture in .NET for win you may get any or unrelated responses.
    No what turn this topic this much diffucult?
    I want your help guys.let me know if i am doing somthing wrong.
    I think in Win application the three layer would be:
    Presentation Layer(PL),
    Bussiness Logic Layer(BLL),
    Data Access Layer(DAL),
    .
    The Data Access Layer must be in a order that would be reusable for entire various win application you want to write without any changes made to it.The only changes would be done in app.config file where your connection string is there.
    I mean the DAL should be organized in a way that would not change a little in various application you use it for.
    It should be like below:

    Code Snippet
    Class DAL
    {
       static Create Connection Method();

       static ExecuteNonQuery Method();
       static ExecuteReader Method();
       static ExecuteScalar Method();
      
    }

    that's it.nothing more.
    The BAL should interact with both PL and DAL.It takes informations from PL and check for some filters if necessary and do some operations like creating Command and attaching the variable to the stored procedure(if used) and at the end only would
    callBig SmileAL . ExecuteNonQuery or DAL.ExecuteScalar or DAL.ExecuteReader.thats it.Now kindly let me know if i am doing the right thing.plz if you know better way explain it with example in here, plz plz don't try to give non related reference.


    Wednesday, February 27, 2008 5:38 AM

Answers

  •  

    I have not read the documentation, but it should be somewhat applicable to both win and web applications at the DAL and BLL layers, with only the PL (UI) that needs to be changed. That’s one of the main benefits of a layered architecture.

     

    The DAL (data access layer) should handle all database I/O (input/output) and return sets of records to the BLL (there are different ways for doing this, I prefer to pass my own objects (classes) and object collections, or you can pass DataSets, etc) The DAL has no knowledge of the BLL or the DAL. There should be a minimum of application specific logic in the DAL. The DAL has methods like:

     

    DAL methods are called from the BLL

     

    public bool Save(CustomClass record)

    {

          //save record to database

          //return true/false if successful  

    }

     

    public CustomClass SelectByID(int id)

    {

          //selects record from database

          //stuffs values into custom record object

          //returns custom record object

    }

     

    The BLL’s (business logic layer) purpose is to make DAL requests and manage the data (manipulate it if necessary) and make business decisions before sending it to the PL. This is where I also handle any unexpected errors, record locks, etc from the DAL. The BLL has knowledge of the DAL and the PL. The BLL has methods like the DAL.

     

    BLL methods are called from the PL (UI)

    BLL makes requests to DAL for data

     

    public bool DAL.Save(CustomClass record)

    {

          //requests DAL to save record object

          //DAL returns bool true/false on success back to BLL

          //BLL returns success to PL, handles error if there is one

    }

     

    public CustomClass SelectByID(int id)

    {

          //requests DAL for a record object

          //DAL returns record object (empty if not found)

          //BLL returns record object to PL, handles error if record empty

    }

     

    The PL (presentation layer) which could be a Windows or Web form, receives data objects or collections from the BLL and populates form controls. The PL might also prepare data for the UI, for example you might want to add functionalty that is specific to a web application. The PL has no knowledge of the DAL. The PL has methods like the BLL and DAL:

     

    PL makes requests to BLL for data

     

    public bool BLL.Save(CustomClass record)

    {

          //PL stuffs form values into a record object

          //BLL returns bool true/false on success back to PL

          //PL informs user if save successful

    }

     

    public CustomClass SelectByID(int id)

    {

          //requests BLL for a record object

          //BLL returns record object (empty if not found)

          //PL stuffs record values into form controls OR displays error if record is empty

     }

     

    This should provide you with the basics, but remember there are many different ways to implement a layered architecture. I actually add a fourth layer; the DDL (data definition layer) which describes the data objects and is utilized by the three other layers.

     

    Hope this helps you to figure things out

    -Duke

     

    Saturday, March 1, 2008 3:22 PM

All replies

  • I am so upset.I thought msdn forum would have some professional and experts that would reply your question fast.but its now 3 day that i have not get an answer.maybe i should ask somewhere else about my problem.
    Saturday, March 1, 2008 5:17 AM
  • The problem is that this is only one of the many ways to access database data, and it isn't always the best one.

     

    Also, your example isn't fleshed out enough. How do you handle multiple database connections. How do you handle OLE connections vs LINQ vs ODBC vs Oracle vs SQL server?

     

    How are you going to deal with transactions?

     

     

    Saturday, March 1, 2008 7:01 AM
  • thanks god you answered.
    by the way could you please explane the best way of implementing 3 Layered Architecture for windows application.i want a detailed example with deep explaination.plz help me.i am searching for over 2 months.but nothing i grab.
    Saturday, March 1, 2008 7:06 AM
  • Here are two sample applications from Microsoft:

    Microsoft .NET Pet Shop
    .NET StockTrader Sample Application

    Here are guides from Microsoft patterns and practices

    Guides
    Saturday, March 1, 2008 9:52 AM
  • you are misunderstand.I want the 3 layer (DAL,BLL,PL) to be explained with an example for windows applicaiton not for asp.net.OK OK.plz help
    Saturday, March 1, 2008 12:07 PM
  •  

    I have not read the documentation, but it should be somewhat applicable to both win and web applications at the DAL and BLL layers, with only the PL (UI) that needs to be changed. That’s one of the main benefits of a layered architecture.

     

    The DAL (data access layer) should handle all database I/O (input/output) and return sets of records to the BLL (there are different ways for doing this, I prefer to pass my own objects (classes) and object collections, or you can pass DataSets, etc) The DAL has no knowledge of the BLL or the DAL. There should be a minimum of application specific logic in the DAL. The DAL has methods like:

     

    DAL methods are called from the BLL

     

    public bool Save(CustomClass record)

    {

          //save record to database

          //return true/false if successful  

    }

     

    public CustomClass SelectByID(int id)

    {

          //selects record from database

          //stuffs values into custom record object

          //returns custom record object

    }

     

    The BLL’s (business logic layer) purpose is to make DAL requests and manage the data (manipulate it if necessary) and make business decisions before sending it to the PL. This is where I also handle any unexpected errors, record locks, etc from the DAL. The BLL has knowledge of the DAL and the PL. The BLL has methods like the DAL.

     

    BLL methods are called from the PL (UI)

    BLL makes requests to DAL for data

     

    public bool DAL.Save(CustomClass record)

    {

          //requests DAL to save record object

          //DAL returns bool true/false on success back to BLL

          //BLL returns success to PL, handles error if there is one

    }

     

    public CustomClass SelectByID(int id)

    {

          //requests DAL for a record object

          //DAL returns record object (empty if not found)

          //BLL returns record object to PL, handles error if record empty

    }

     

    The PL (presentation layer) which could be a Windows or Web form, receives data objects or collections from the BLL and populates form controls. The PL might also prepare data for the UI, for example you might want to add functionalty that is specific to a web application. The PL has no knowledge of the DAL. The PL has methods like the BLL and DAL:

     

    PL makes requests to BLL for data

     

    public bool BLL.Save(CustomClass record)

    {

          //PL stuffs form values into a record object

          //BLL returns bool true/false on success back to PL

          //PL informs user if save successful

    }

     

    public CustomClass SelectByID(int id)

    {

          //requests BLL for a record object

          //BLL returns record object (empty if not found)

          //PL stuffs record values into form controls OR displays error if record is empty

     }

     

    This should provide you with the basics, but remember there are many different ways to implement a layered architecture. I actually add a fourth layer; the DDL (data definition layer) which describes the data objects and is utilized by the three other layers.

     

    Hope this helps you to figure things out

    -Duke

     

    Saturday, March 1, 2008 3:22 PM
  • The guides explain 3 layer and examples show how to apply them in web and windows applications. What else do you need?
    Saturday, March 1, 2008 5:49 PM
  • Thanks Duke,But i need a complete Explanation and Example and deep Detail about the code.You couldn't realize that how many programmers of .NET in my country lack from this Architecture.No one knows How to implement a
    Three Layer Architecture in Windows Application.Actually Me and my friends are seeking to learn that.Ok Now would anybody do me a favor and Give a Complete Example in this forum and just over here(no giving links to other websites) and explaine it .Please Help US and ME.Please Help.
    Sunday, March 2, 2008 5:55 AM
  • hi all
    excu for i can not speak english CareFully
    what the purpose of three layer ?

    1.  Managed All DataConnection Code And Do it From One Place 
     
        Reasons  
        a - when i need change the Data server or other changeing   ... i change one Place

        b - we can use Sevral Server And Sevral database
             for Example .
            
            SQL Server - Oracel - Access - XML - Personal Server ...    
         
            Authentication Database  -   Report & recovery - Communication Information - Personalize and UI - ...

      i think write this code is beter one Class For DAL Layer

    DAL

      class  DBase        // dataBase
      {
              ServerType   // use the  enum {SQLServer,SqlExpress,Oracel,...}
              ServiceType  // use the enum {Authentication, Report,Communication,...}

              State            // 
               
              TransactionQroup   //  is a DictianaryBase class for Managed Transactions 

               Add a Command or CommandGroup to Transaction Group with Priority level of observance

             delegate SqlRunCommand
             delegate OracelRunCommand
             delegate XMLCommand
             delegate ... other Server


                      

               
       }
       class TransactionQroup : DictianaryBase // Dictianray of CommandGroup Class
       {
           .
           .    Dictionary code
           .

           Run function
           Recovery this
           Return Result for Base Class       
         
        }
       class CommandGroup  queue of the Command
       class SQl    // run the SqlCommand and more service of Sql
       class OleDb           //   ....
       class Oracel          //  ...
       class XML


       BLL or UI
         if  Dal Layer codes is useful i write this  . thanks

        
    Tuesday, November 24, 2009 5:03 PM
  • Or you could simply use a DL generator with a consistent API like SubSonic.  That way if your DL changes you can just re-generate the DL, you make the same kind of calls with the same API, and its owned by MS and follows their design guidelines for DL generation.
    Good coding involves knowing one's logical limits and expanding them as necessary.
    Tuesday, November 24, 2009 5:10 PM
  • when you Create Dal for first time you can yous this all time this 
    you can create PL o BLL by Code Genrator but i do not recommend 

    Wednesday, November 25, 2009 6:06 AM