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. Design and Architecture
  4. Loading objects

Loading objects

Scheduled Pinned Locked Moved Design and Architecture
questiondesigntutorialdiscussion
5 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.
  • C Offline
    C Offline
    CodingYoshi
    wrote on last edited by
    #1

    A common task we always have to accomplish is to allow users to edit objects from the UI. For example, lets say I have an employee class with the regular properties. The UI will have textboxes and other controls to display the properties. A user can select an employee by name from a listbox, treeview, combobox or whatever (not important to this question) and the form will display the employee. These are different approaches I have been taking to display the employee and I was wondering which is a better approach or if you can recommend one: 1. Create a property within the employeeForm called Employee and when it is set the form will call its private ReLoad() method and display the employee. 2. Create a property as mentioned in 1, but do not ReLoad in the setter, instead make the ReLoad method public and clients should call the ReLoad method after setting the employee. 3. Forget the property altogether and just have a method called Load(Employee emp). This is basically a method which takes employee as a parameter and then displays it. What do you think?

    L 1 Reply Last reply
    0
    • C CodingYoshi

      A common task we always have to accomplish is to allow users to edit objects from the UI. For example, lets say I have an employee class with the regular properties. The UI will have textboxes and other controls to display the properties. A user can select an employee by name from a listbox, treeview, combobox or whatever (not important to this question) and the form will display the employee. These are different approaches I have been taking to display the employee and I was wondering which is a better approach or if you can recommend one: 1. Create a property within the employeeForm called Employee and when it is set the form will call its private ReLoad() method and display the employee. 2. Create a property as mentioned in 1, but do not ReLoad in the setter, instead make the ReLoad method public and clients should call the ReLoad method after setting the employee. 3. Forget the property altogether and just have a method called Load(Employee emp). This is basically a method which takes employee as a parameter and then displays it. What do you think?

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      CodingYoshi wrote:

      What do you think?

      It sounds like you might not be familiar with the Model-View-Controller design pattern[^]. Good luck

      led mike

      C 1 Reply Last reply
      0
      • L led mike

        CodingYoshi wrote:

        What do you think?

        It sounds like you might not be familiar with the Model-View-Controller design pattern[^]. Good luck

        led mike

        C Offline
        C Offline
        CodingYoshi
        wrote on last edited by
        #3

        I am very familiar with MVC and use it all the time.

        L 1 Reply Last reply
        0
        • C CodingYoshi

          I am very familiar with MVC and use it all the time.

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          CodingYoshi wrote:

          I am very familiar with MVC and use it all the time.

          Really? How are any of the options you posted in your first post, part of the MVC design? I don't see it.

          led mike

          C 1 Reply Last reply
          0
          • L led mike

            CodingYoshi wrote:

            I am very familiar with MVC and use it all the time.

            Really? How are any of the options you posted in your first post, part of the MVC design? I don't see it.

            led mike

            C Offline
            C Offline
            CodingYoshi
            wrote on last edited by
            #5

            led mike wrote:

            How are any of the options you posted in your first post, part of the MVC design?

            I never said my options had anything to do with MVC pattern. I use MVC pattern but in this case my question is not about MVC. My question is closely related to the observer pattern. You have an object of a class which is being observed by the form by subscribing to its events. Now when the user selects a different object from a treeview (or whatever), this class will become the new object the form is observing and the form should display its data. But the form can only do so once the object fires the event. But the object will fire the event when its state changes so the form has to wait until the user changes the state of the object. So now we are stuck because this is what has been happening so far: First an object was selected from the treeview. The object is sent to the form. The form subscribes to its events. The events are not fired so how do we display it? The solution I came up with is to trigger the event through a public method--just like we can trigger events in .NET by calling OnPaint. Now the form can display the data. So I think the answer to my question is to set the property and send a reference of the object to the form. Afterwards, force the objects event by triggering it through a public method. But I am still not sure if this a good solution.

            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