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. Web Development
  3. ASP.NET
  4. Question on entity class in the layer

Question on entity class in the layer

Scheduled Pinned Locked Moved ASP.NET
questionbusinesshelp
6 Posts 2 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.
  • D Offline
    D Offline
    DotNetXenon
    wrote on last edited by
    #1

    I have created a web app with 4 layers : Presentation - Business - Services - Data. I have Business.Entities project which is added to Business layer and have Employee class in it. I also have DataAccess.Entities and Presentation.Entities and have added Employee.cs in there also. Now in project references I have added Presentation project reference in Business, Business project reference in DataAccess. Is this approach correct? My Question is, Should Employee.cs class be added to each project entities like I did above or should Employee.cs be added to only Business.Entities project and Business.Entities proj reference be added to all projects? I got this question because the 2nd approach was used in a project I downloaded from internet. Please help.

    ------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates

    P 1 Reply Last reply
    0
    • D DotNetXenon

      I have created a web app with 4 layers : Presentation - Business - Services - Data. I have Business.Entities project which is added to Business layer and have Employee class in it. I also have DataAccess.Entities and Presentation.Entities and have added Employee.cs in there also. Now in project references I have added Presentation project reference in Business, Business project reference in DataAccess. Is this approach correct? My Question is, Should Employee.cs class be added to each project entities like I did above or should Employee.cs be added to only Business.Entities project and Business.Entities proj reference be added to all projects? I got this question because the 2nd approach was used in a project I downloaded from internet. Please help.

      ------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates

      P Offline
      P Offline
      Pravin Patil Mumbai
      wrote on last edited by
      #2

      You should follow one basic principle : Do not write redundant code. i.e. If you add Employee.cs to all the projects it would simply be the copy paste. Any change in this class will force you to change it in all the projects. My recommendation : As you have mentioned, you have Business.Entity project, add all the entities including Employee.cs in this project only. And then this project be added as a reference to rest of the projects. Hope this helps. All the best.

      I quit being afraid when my first venture failed and the sky didn't fall down.

      D 1 Reply Last reply
      0
      • P Pravin Patil Mumbai

        You should follow one basic principle : Do not write redundant code. i.e. If you add Employee.cs to all the projects it would simply be the copy paste. Any change in this class will force you to change it in all the projects. My recommendation : As you have mentioned, you have Business.Entity project, add all the entities including Employee.cs in this project only. And then this project be added as a reference to rest of the projects. Hope this helps. All the best.

        I quit being afraid when my first venture failed and the sky didn't fall down.

        D Offline
        D Offline
        DotNetXenon
        wrote on last edited by
        #3

        Thanks Pravin. You pointed out not to write redundant code and that is excellent. But I have a question here. When following layers, do we not have to add the reference of Business in DAL, Presentation in Business etc. so that the flow will be maintained. If Business project is added as reference on all projects, would the layered architecture model not be affected?

        ------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates

        P 1 Reply Last reply
        0
        • D DotNetXenon

          Thanks Pravin. You pointed out not to write redundant code and that is excellent. But I have a question here. When following layers, do we not have to add the reference of Business in DAL, Presentation in Business etc. so that the flow will be maintained. If Business project is added as reference on all projects, would the layered architecture model not be affected?

          ------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates

          P Offline
          P Offline
          Pravin Patil Mumbai
          wrote on last edited by
          #4

          I highly appreciate your response. You raised a very correct and genuine concern. You have two options. Options 1: Keep the business entity and business logic altogether different. In business entity you will have only public properties exposed. in simple terms it will act as a container for the data that flows through the layers. And business logic will have the core busines logic in it. Now, in this approach you only need to add the reference of Business entity in all the layers. Presentation, Business and DAL. Options 2: You will have no difference between Business logic and Entity. You can merge these two layers. i.e. Public properties and the business logic pertaining to that will be in the same class. Validation also goes in the same class. In this case you will have to add reference of this layer to both presentation and Data layer. Both these approaches are used extensively in the Software Industry. However, second approach is much more extensively used, even it is used in MVC, MVP and MVVP architecture. Hope this helps. All the best.

          I quit being afraid when my first venture failed and the sky didn't fall down.

          D 1 Reply Last reply
          0
          • P Pravin Patil Mumbai

            I highly appreciate your response. You raised a very correct and genuine concern. You have two options. Options 1: Keep the business entity and business logic altogether different. In business entity you will have only public properties exposed. in simple terms it will act as a container for the data that flows through the layers. And business logic will have the core busines logic in it. Now, in this approach you only need to add the reference of Business entity in all the layers. Presentation, Business and DAL. Options 2: You will have no difference between Business logic and Entity. You can merge these two layers. i.e. Public properties and the business logic pertaining to that will be in the same class. Validation also goes in the same class. In this case you will have to add reference of this layer to both presentation and Data layer. Both these approaches are used extensively in the Software Industry. However, second approach is much more extensively used, even it is used in MVC, MVP and MVVP architecture. Hope this helps. All the best.

            I quit being afraid when my first venture failed and the sky didn't fall down.

            D Offline
            D Offline
            DotNetXenon
            wrote on last edited by
            #5

            Thank you so much.

            ------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates

            P 1 Reply Last reply
            0
            • D DotNetXenon

              Thank you so much.

              ------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates

              P Offline
              P Offline
              Pravin Patil Mumbai
              wrote on last edited by
              #6

              My pleasure.......

              I quit being afraid when my first venture failed and the sky didn't fall down.

              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