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. Hierarchical domain object creation not SOLID

Hierarchical domain object creation not SOLID

Scheduled Pinned Locked Moved .NET (Core and Framework)
designarchitecturequestiondatabaseregex
5 Posts 3 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.
  • P Offline
    P Offline
    Peter Trevor
    wrote on last edited by
    #1

    I have a project where the data is intended to be hierarchical in nature. The obvious solution seemed to be to create a hierarchical set of domain objects: when you instantiate the root object (with its key) it goes to the database to get its properties and a list of children. It then instantiates a child object for each and maintains them in a collection. As each child object is instantiated the process repeats itself recursively. All well and good. Except it doesn’t follow the principles of SOLID: these domain objects contain data access code. What is the correct design (or design pattern) here? - Do I ignore SOLID in this case? - Have a parallel hierarchy of data access helper objects (one for each domain object)? - Do I keep all the data access code in the object that created the root domain object (ensuring it is thread-safe) and reference it from the domain objects using callbacks? - Encapsulate the data access code in a thread-safe singleton helper? - Is my basic approach flawed? - Something else? (The database hasn’t been designed yet, and the domain objects will need to be able to save changes ... more data access code. These domain objects will be accessed a number of ways including via a treeview in the UI.) Surely this is something that must have come up many times before.

    T 1 Reply Last reply
    0
    • P Peter Trevor

      I have a project where the data is intended to be hierarchical in nature. The obvious solution seemed to be to create a hierarchical set of domain objects: when you instantiate the root object (with its key) it goes to the database to get its properties and a list of children. It then instantiates a child object for each and maintains them in a collection. As each child object is instantiated the process repeats itself recursively. All well and good. Except it doesn’t follow the principles of SOLID: these domain objects contain data access code. What is the correct design (or design pattern) here? - Do I ignore SOLID in this case? - Have a parallel hierarchy of data access helper objects (one for each domain object)? - Do I keep all the data access code in the object that created the root domain object (ensuring it is thread-safe) and reference it from the domain objects using callbacks? - Encapsulate the data access code in a thread-safe singleton helper? - Is my basic approach flawed? - Something else? (The database hasn’t been designed yet, and the domain objects will need to be able to save changes ... more data access code. These domain objects will be accessed a number of ways including via a treeview in the UI.) Surely this is something that must have come up many times before.

      T Offline
      T Offline
      TheyCallMeMrJames
      wrote on last edited by
      #2

      If you implement the children objects as interfaces (and you should, for the D in SOLID) then you can just leave them as placeholders until they are accessed in the tree. I have also worked on a couple projects where you push an IDataAccessSomethingOrOther into a presenter or controller layer. As the view events are raised that require loading, methods on the IDataThingyIMentionedEarlier are invoked by the presenter/controller that would load those child objects up. My advice would be to keep your data out of your model objects. Cheers,

      They Call me Mister James

      D 1 Reply Last reply
      0
      • T TheyCallMeMrJames

        If you implement the children objects as interfaces (and you should, for the D in SOLID) then you can just leave them as placeholders until they are accessed in the tree. I have also worked on a couple projects where you push an IDataAccessSomethingOrOther into a presenter or controller layer. As the view events are raised that require loading, methods on the IDataThingyIMentionedEarlier are invoked by the presenter/controller that would load those child objects up. My advice would be to keep your data out of your model objects. Cheers,

        They Call me Mister James

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

        Hi TCMMJ, You appear to have provided an answer to an entirely different thread here.

        T 1 Reply Last reply
        0
        • D DotNetJoe

          Hi TCMMJ, You appear to have provided an answer to an entirely different thread here.

          T Offline
          T Offline
          TheyCallMeMrJames
          wrote on last edited by
          #4

          Really? :doh: Are you seeing it wrapped across the forum page? Maybe I'm seeing it wrong, but I think I contributed to part of the answer. :confused:

          They Call me Mister James

          D 1 Reply Last reply
          0
          • T TheyCallMeMrJames

            Really? :doh: Are you seeing it wrapped across the forum page? Maybe I'm seeing it wrong, but I think I contributed to part of the answer. :confused:

            They Call me Mister James

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

            Sorry, I think your right, the forum was wrapping, making your answer appear under my question - bizzarre??

            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