Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Three tier architecture, database access layer pattern [modified]

Three tier architecture, database access layer pattern [modified]

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasecsharpc++dotnetdesign
15 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Julen

    Hi, I am designing an architecture in .NET framework. I use the Three tier model to design my application but I have a concern about how is the way to properly model the access to database layer. I have separate DLL for each layer. In my business layer I want to access the database, for example to add new registry in a way that the members are not passed each one in a parameter but all in a single object. For example:

    namespace myapp.bussines_layer
    {
    class Point
    {
    int x;
    int y;

    MyDatabase db = new MyDatabase();

    //I want this...
    void InsertInDatabase()
    {
    db.NewRowInDB(this);
    }

    //... instead of this
    void InsertInDatabase()
    {
    db.NewRowInDB(this.x, this.y);
    }
    }
    }

    The thing is that this way I have circular dependency because Point knows MyDatabase; and MyDatabase has to know Point in order to recognize Point as an parameter in the function. Does my idea fit correctly in the good practices and designs to access databases? Is better design to pass all the parameters as native types (even when the amount os parameter is high)?? I would be very grateful if anyone could help me and/or give me references to good design patterns with the connection between business and database layers. Thank you very much in advance. Julen.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    Julen wrote:

    The thing is that this way I have circular dependency because Point knows MyDatabase; and MyDatabase has to know Point in order to recognize Point as an parameter in the function.

    Point is a predefined type; it is declared externally of both DLL's. You can do the same thing for your own classes, to avoid circular references.

    Julen wrote:

    I would be very grateful if anyone could help me and/or give me references to good design patterns with the connection between business and database layers.

    The dOOdads[^] architecture was a nice example. It's deprecated by now, but it's clean and readable code. Fastest way to dive into that code is to use the myGeneration application to generate a small testapplication that contains them dOOdads.

    I are troll :)

    J 1 Reply Last reply
    0
    • L Lost User

      Julen wrote:

      The thing is that this way I have circular dependency because Point knows MyDatabase; and MyDatabase has to know Point in order to recognize Point as an parameter in the function.

      Point is a predefined type; it is declared externally of both DLL's. You can do the same thing for your own classes, to avoid circular references.

      Julen wrote:

      I would be very grateful if anyone could help me and/or give me references to good design patterns with the connection between business and database layers.

      The dOOdads[^] architecture was a nice example. It's deprecated by now, but it's clean and readable code. Fastest way to dive into that code is to use the myGeneration application to generate a small testapplication that contains them dOOdads.

      I are troll :)

      J Offline
      J Offline
      Julen
      wrote on last edited by
      #3

      Eddy Vluggen wrote:

      Point is a predefined type; it is declared externally of both DLL's. You can do the same thing for your own classes, to avoid circular references.

      In this case Point is just an example; my class is one of my own that has at least 10 members. If I include this class in both DLL, would'n I be breaking the separation between the business and data layer?

      L P 2 Replies Last reply
      0
      • J Julen

        Eddy Vluggen wrote:

        Point is a predefined type; it is declared externally of both DLL's. You can do the same thing for your own classes, to avoid circular references.

        In this case Point is just an example; my class is one of my own that has at least 10 members. If I include this class in both DLL, would'n I be breaking the separation between the business and data layer?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #4

        Create a separate DLL for OwnClass, and reference it from both assemblies. The separation is one of responsibilities, not of classes; you're going to pass data from one DLL to another (or, from one layer to another) - and you'll need some common ground for them to talk to each other. In pseudocode;

        class Person { string Name; }

        class DALPerson: Person
        {
        public DALPerson(string connectionString)
        {
        Name = // load from database
        }
        }

        class BLPerson: DALPerson
        {
        public override ToString()
        {
        return "High Lord " + Name;
        }
        }

        We have met the enemy, and he is us :)

        V 1 Reply Last reply
        0
        • J Julen

          Hi, I am designing an architecture in .NET framework. I use the Three tier model to design my application but I have a concern about how is the way to properly model the access to database layer. I have separate DLL for each layer. In my business layer I want to access the database, for example to add new registry in a way that the members are not passed each one in a parameter but all in a single object. For example:

          namespace myapp.bussines_layer
          {
          class Point
          {
          int x;
          int y;

          MyDatabase db = new MyDatabase();

          //I want this...
          void InsertInDatabase()
          {
          db.NewRowInDB(this);
          }

          //... instead of this
          void InsertInDatabase()
          {
          db.NewRowInDB(this.x, this.y);
          }
          }
          }

          The thing is that this way I have circular dependency because Point knows MyDatabase; and MyDatabase has to know Point in order to recognize Point as an parameter in the function. Does my idea fit correctly in the good practices and designs to access databases? Is better design to pass all the parameters as native types (even when the amount os parameter is high)?? I would be very grateful if anyone could help me and/or give me references to good design patterns with the connection between business and database layers. Thank you very much in advance. Julen.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #5

          Julen wrote:

          I use the tree tier model

          It's "three-tier", as in the number 3, not "tree tier".

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          modified on Sunday, June 21, 2009 11:48 PM

          J 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Julen wrote:

            I use the tree tier model

            It's "three-tier", as in the number 3, not "tree tier".

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            modified on Sunday, June 21, 2009 11:48 PM

            J Offline
            J Offline
            Julen
            wrote on last edited by
            #6

            Dave Kreskowiak wrote:

            It's "three-tier", as in the number 3, not "tree tier".

            Sorry for the spelling. :-O I don't dislike creating a separate DLL to come to a common ground between layers. So, if I have three tier architecture; will I have 5 DLL? Three for the layers themself; and two for the common grounds? Presentation layer -- Common ground 1 -- Bussiness layer -- Common ground 2 -- Data Layer Could recommend me an article, reference, matter on this issue? :) Thanks!

            S 1 Reply Last reply
            0
            • J Julen

              Dave Kreskowiak wrote:

              It's "three-tier", as in the number 3, not "tree tier".

              Sorry for the spelling. :-O I don't dislike creating a separate DLL to come to a common ground between layers. So, if I have three tier architecture; will I have 5 DLL? Three for the layers themself; and two for the common grounds? Presentation layer -- Common ground 1 -- Bussiness layer -- Common ground 2 -- Data Layer Could recommend me an article, reference, matter on this issue? :) Thanks!

              S Offline
              S Offline
              Shukla Rahul
              wrote on last edited by
              #7

              Create a Common library for Data Transfer objects and share it among all layers. So this would be              (Data Transfer Objects)                    (Data Transfer Objects) Data Layer -----------------------> Business Layer ------------------------> UI Layer

              J 1 Reply Last reply
              0
              • S Shukla Rahul

                Create a Common library for Data Transfer objects and share it among all layers. So this would be              (Data Transfer Objects)                    (Data Transfer Objects) Data Layer -----------------------> Business Layer ------------------------> UI Layer

                J Offline
                J Offline
                Julen
                wrote on last edited by
                #8

                Shukla Rahul wrote:

                Create a Common library for Data Transfer objects and share it among all layers. So this would be (Data Transfer Objects) (Data Transfer Objects) Data Layer -----------------------> Business Layer ------------------------> UI Layer

                To create those Data Transfer Objects, is there a pattern or standard design to create them? Also, regarding the picture; do you mean with the arrows that the data access layer has a reference to business layer instead of reverse? Thanks!

                S 1 Reply Last reply
                0
                • L Lost User

                  Create a separate DLL for OwnClass, and reference it from both assemblies. The separation is one of responsibilities, not of classes; you're going to pass data from one DLL to another (or, from one layer to another) - and you'll need some common ground for them to talk to each other. In pseudocode;

                  class Person { string Name; }

                  class DALPerson: Person
                  {
                  public DALPerson(string connectionString)
                  {
                  Name = // load from database
                  }
                  }

                  class BLPerson: DALPerson
                  {
                  public override ToString()
                  {
                  return "High Lord " + Name;
                  }
                  }

                  We have met the enemy, and he is us :)

                  V Offline
                  V Offline
                  vasanth1111
                  wrote on last edited by
                  #9

                  its very simple ;P ;P

                  L 1 Reply Last reply
                  0
                  • J Julen

                    Hi, I am designing an architecture in .NET framework. I use the Three tier model to design my application but I have a concern about how is the way to properly model the access to database layer. I have separate DLL for each layer. In my business layer I want to access the database, for example to add new registry in a way that the members are not passed each one in a parameter but all in a single object. For example:

                    namespace myapp.bussines_layer
                    {
                    class Point
                    {
                    int x;
                    int y;

                    MyDatabase db = new MyDatabase();

                    //I want this...
                    void InsertInDatabase()
                    {
                    db.NewRowInDB(this);
                    }

                    //... instead of this
                    void InsertInDatabase()
                    {
                    db.NewRowInDB(this.x, this.y);
                    }
                    }
                    }

                    The thing is that this way I have circular dependency because Point knows MyDatabase; and MyDatabase has to know Point in order to recognize Point as an parameter in the function. Does my idea fit correctly in the good practices and designs to access databases? Is better design to pass all the parameters as native types (even when the amount os parameter is high)?? I would be very grateful if anyone could help me and/or give me references to good design patterns with the connection between business and database layers. Thank you very much in advance. Julen.

                    P Offline
                    P Offline
                    Pete OHanlon
                    wrote on last edited by
                    #10

                    This sounds like a serious case of entanglement. Why should Point know about MyDatabase and why should MyDatabase know about Point? What you might want to look at instead, is using interfaces to control the way things interact, and then code against the interface.

                    "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                    As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                    My blog | My articles | MoXAML PowerToys | Onyx

                    1 Reply Last reply
                    0
                    • J Julen

                      Shukla Rahul wrote:

                      Create a Common library for Data Transfer objects and share it among all layers. So this would be (Data Transfer Objects) (Data Transfer Objects) Data Layer -----------------------> Business Layer ------------------------> UI Layer

                      To create those Data Transfer Objects, is there a pattern or standard design to create them? Also, regarding the picture; do you mean with the arrows that the data access layer has a reference to business layer instead of reverse? Thanks!

                      S Offline
                      S Offline
                      Shukla Rahul
                      wrote on last edited by
                      #11

                      You can create a project class library project which holds such classes. Provide the reference of this project in all layers. Sorry, the arrow shows the flow of the data objects not the reference. Reference would be as follows Data Access Layer - Ref of common Business Layer - Ref of Data Access Layer and Ref of Common UI - Ref of Business Layer & ref of Common Download sample project from here. -Rahul Shukla

                      1 Reply Last reply
                      0
                      • J Julen

                        Eddy Vluggen wrote:

                        Point is a predefined type; it is declared externally of both DLL's. You can do the same thing for your own classes, to avoid circular references.

                        In this case Point is just an example; my class is one of my own that has at least 10 members. If I include this class in both DLL, would'n I be breaking the separation between the business and data layer?

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #12

                        Julen wrote:

                        would'n I be breaking the separation between the business and data layer?

                        Not necessarily. As mentioned by others, the class could be external to both layers, or it could be defined in the lowest layer that uses it (probably the business layer). And layers aren't necessarily tiers; don't confuse the two concepts.

                        J 1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          Julen wrote:

                          would'n I be breaking the separation between the business and data layer?

                          Not necessarily. As mentioned by others, the class could be external to both layers, or it could be defined in the lowest layer that uses it (probably the business layer). And layers aren't necessarily tiers; don't confuse the two concepts.

                          J Offline
                          J Offline
                          Julen
                          wrote on last edited by
                          #13

                          Oh; that's nice to say because I thought both concepts mean the same. What is the difference?

                          L 1 Reply Last reply
                          0
                          • V vasanth1111

                            its very simple ;P ;P

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #14

                            Once you know it, yes :)

                            I are troll :)

                            1 Reply Last reply
                            0
                            • J Julen

                              Oh; that's nice to say because I thought both concepts mean the same. What is the difference?

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #15

                              The logical layers are the conceptual division, the tiers are the physical division. (Source[^])

                              I are troll :)

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups