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. C#
  4. Binding Business Objects to Controls (or not)

Binding Business Objects to Controls (or not)

Scheduled Pinned Locked Moved C#
questioncsharpcsswpfwcf
3 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.
  • J Offline
    J Offline
    Jan Limpens
    wrote on last edited by
    #1

    Hello, I have a more ore or less complicated business object, that looks similar to this: has some properties (id, pubdate...) and a list of s each has a language, a title and a description Entry also has a list of s each , has a List of s with language, title and description To edit the objects properties I created a similar structure of controls has some Textboxes, a Tabstrip, holdig Tabs corresponding to s, again holding some Textboxes, and a list of s with their s. The question is, should the control A) know of the business object it represents? Should I instantiate EntryControl like this? Entry e = Entry.GetEntry("abc"); EntryControl ec = new EntryControl(e); and "inside" of EntryControl my Properties would be public string Id { get { return entry.Id; } set { entry Id = value; TextBoxId.Text = value; } } and have problems, once the user edits the fields, a call to Id, would still yield the object's value and not the textbox' new text value. But I'd have the advantage (still in Entry) that I could much better encapsulate the child controls creation and logic. public EntryControl(Entry entry) { VersionControl versionControl = new VersionControl(); versionControl.Versions = entry.Versions // now I can encapsulate // everything onwards in // VersionControl } or B) should my Controls be completely agnostic containers of agnostic sub controls (as the generic .net controls are) Instead: class EntryControl { private Textbox textBoxId, textBoxPubDate; public string Id { get {return textBoxId.Text; } set {textBoxId.Text = value; } } public VersionControl VersionControl; } class Client { void DoSomething() { Entry e = Entry.GetEntry("abc"); EntryControl ec = new EntryControl(); ec.Id = e.Id; ec.VersionControl = new VersionControl(); foreach(Version v in e.Versions) { VersionTab tab = new VersionTab(); // will be difficult to // reconstruct e later. What // if the user inserts a new version // in the middle...? tab.Title = v.Title; ec.VersionControl.Tabs.Add(tab); } // ... } } What is your opinion? What

    E 1 Reply Last reply
    0
    • J Jan Limpens

      Hello, I have a more ore or less complicated business object, that looks similar to this: has some properties (id, pubdate...) and a list of s each has a language, a title and a description Entry also has a list of s each , has a List of s with language, title and description To edit the objects properties I created a similar structure of controls has some Textboxes, a Tabstrip, holdig Tabs corresponding to s, again holding some Textboxes, and a list of s with their s. The question is, should the control A) know of the business object it represents? Should I instantiate EntryControl like this? Entry e = Entry.GetEntry("abc"); EntryControl ec = new EntryControl(e); and "inside" of EntryControl my Properties would be public string Id { get { return entry.Id; } set { entry Id = value; TextBoxId.Text = value; } } and have problems, once the user edits the fields, a call to Id, would still yield the object's value and not the textbox' new text value. But I'd have the advantage (still in Entry) that I could much better encapsulate the child controls creation and logic. public EntryControl(Entry entry) { VersionControl versionControl = new VersionControl(); versionControl.Versions = entry.Versions // now I can encapsulate // everything onwards in // VersionControl } or B) should my Controls be completely agnostic containers of agnostic sub controls (as the generic .net controls are) Instead: class EntryControl { private Textbox textBoxId, textBoxPubDate; public string Id { get {return textBoxId.Text; } set {textBoxId.Text = value; } } public VersionControl VersionControl; } class Client { void DoSomething() { Entry e = Entry.GetEntry("abc"); EntryControl ec = new EntryControl(); ec.Id = e.Id; ec.VersionControl = new VersionControl(); foreach(Version v in e.Versions) { VersionTab tab = new VersionTab(); // will be difficult to // reconstruct e later. What // if the user inserts a new version // in the middle...? tab.Title = v.Title; ec.VersionControl.Tabs.Add(tab); } // ... } } What is your opinion? What

      E Offline
      E Offline
      Ed Poore
      wrote on last edited by
      #2

      A - the business object layer shouldn't know anything of how the data will be presented.


      If you're stuck in a rut: 1) Consult the documentation* 2) Google it 3) Ask a sensible question 4) Try an ancient ritualistic knowledge summoning (:badger::badger::badger:) dance :jig: 5) Phone :bob: * - If the documentation is MSDN > 6.0 then forget it!

      J 1 Reply Last reply
      0
      • E Ed Poore

        A - the business object layer shouldn't know anything of how the data will be presented.


        If you're stuck in a rut: 1) Consult the documentation* 2) Google it 3) Ask a sensible question 4) Try an ancient ritualistic knowledge summoning (:badger::badger::badger:) dance :jig: 5) Phone :bob: * - If the documentation is MSDN > 6.0 then forget it!

        J Offline
        J Offline
        Jan Limpens
        wrote on last edited by
        #3

        Neither in A or B the businesslayer has any knowledge of it's representation (in my examples)

        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