[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [ajug-members]: Sharing data among Swing windows
Stefan Baramov said:
> You can use Singleton [GoF95] to share global objects. Luckily, Swing is a
> single threaded so you would not need to synchronize your global objects.
> Another useful pattern is the Madiator [GoF95]. You can read about these
> patterns in books such as "Patterns in Java" , ISBN 0-471-25839-3
Ah, ok...so let me make sure I follow. Taking my example, I could create
a Connector class that implemented the Singleton pattern and would handle
requests from various Swing windows. The Connector class would maintain
one static field that contained a static instantiation of itself and that
its constructors could check to see if it was already instantiated. If it
was, then return a reference to that static field, else, instantiate,
store a ref in that static field, and then return a reference.
Is that on correct?
What about application contants such as log file name, common directory
paths, etc. Would it be best to create an AppConfiguration class (also
implementing the Singleton pattern), have it abstract out the method by
which you store the common data (properties file, etc), and have all of
your other classes (windows) query it for the info?
Thanks for your continued help.