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