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. Visual Basic
  4. Is this bad practice?

Is this bad practice?

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasewinformsdata-structuresquestion
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.
  • L Offline
    L Offline
    Len Miller
    wrote on last edited by
    #1

    I am creating an MDI database-driven app in WinForms (VB .NET 2003). There are many objects that I would like to have available / around to all child forms for the life of the application: - DatabaseProviderFactory - Connection String - ResourceManager object - A custom message handler object - etc,etc. I figured during the mainform (MDI) load, I would create / instantiate these objects and put them in public shared properties of the main form. The child forms would reference the main form properties for their objects. Is this considered "bad practice"? Is there a better way to do this? Thanks, -Len Miller "If I had eight hours to chop down a tree, I'd spend six sharpening my axe." -Abraham Lincoln

    S 1 Reply Last reply
    0
    • L Len Miller

      I am creating an MDI database-driven app in WinForms (VB .NET 2003). There are many objects that I would like to have available / around to all child forms for the life of the application: - DatabaseProviderFactory - Connection String - ResourceManager object - A custom message handler object - etc,etc. I figured during the mainform (MDI) load, I would create / instantiate these objects and put them in public shared properties of the main form. The child forms would reference the main form properties for their objects. Is this considered "bad practice"? Is there a better way to do this? Thanks, -Len Miller "If I had eight hours to chop down a tree, I'd spend six sharpening my axe." -Abraham Lincoln

      S Offline
      S Offline
      Steven Campbell
      wrote on last edited by
      #2

      Rather than tying everything to the main form, a better solution may be to either * design each of these objects as Singletons[^], or * just use shared methods, so that you do not need a specific object instance.


      my blog

      L 1 Reply Last reply
      0
      • S Steven Campbell

        Rather than tying everything to the main form, a better solution may be to either * design each of these objects as Singletons[^], or * just use shared methods, so that you do not need a specific object instance.


        my blog

        L Offline
        L Offline
        Len Miller
        wrote on last edited by
        #3

        Steve, Hmmm, interesting. I will investigate the Singletons concept more - maybe that is my answer - I need to educate myself a bit on that. I do not think the shared methods concept will work (If I understand you correctly), because these "global" objects really need to be object instances. For example, my custom message object contains a dialog form, properties that control the "mailto:" text behind a "Contact Tech Support" link label, the icon / logo, the buttons (yes, no, cancel, etc), the existance of a "<< Details" button, etc. This really can't be handled in a shared method (I don't think). Now, the connection string can, maybe the ResourceManager object can... Thanks a bunch for your reply Steve! Any more wisdom or ideas you can toss me is always appreciated. Thanks, -Len Miller "If I had eight hours to chop down a tree, I'd spend six sharpening my axe." -Abraham Lincoln

        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