Global data was a natural, efficient and invaluable way to share data but
open to abuse. The public static method of C# seems like an effective
substitute. I have asked before in this group what would be the
recommended
way to share data collected by a dialog box. The only suggestion was to
instantiate the classes that need to know and pass the data into the
constructors.
There is so much traffic on this newsgroup, topics drift so frequently,
and subjects so often don't reflect what's actually in the thread (or even
the first post in a thread) that not every question is seen by every
person reading the newsgroup.
Personally, I would never recommend that if a dialog box gathers
information to be shared by multiple classes, that the correct solution is
to have the dialog box instantiate all of those classes and initialize
them with the data from the dialog box. I'm surprised you even used the
word "sound" to describe the idea. It has all of the disadvantages you
describe, and is every bit as problematic as you think it is.
But that doesn't mean you need global variables. Data should be stored in
an object that matches the visibility and lifetime of that data. In the
case of a dialog box, some component of the code created and displayed
that dialog box, and generally that component is a likely candidate for
storage of the data obtained by the dialog box.
How it does that depends on the rest of the way that data is used. If the
data is needed only temporarily to instantiate other objects, then the
code calling the dialog box is probably also the code instantiating the
other objects. So it should store the data from the dialog box long
enough to do that.
Another scenario is that the dialog box allows the user to initialize some
default settings that persist through the lifetime of the application. In
that case, the data might be more appropriately stored in the main
Application class, or in the Properties.Settings.Default class (if they
are to be persistent from one execution session to another, for example).
There are no hard and fast rules...it just depends on what you intend to
do with the data. But even at the simplest level, the Application object
makes a perfectly fine repository for things that would have been global
variables in a non-OOP environment. (And of course it goes without saying
that the *only* data that should be stored in the Application object are
data that truly do need to persist for the entire lifetime of the
application).
Pete