[Bluej-discuss] style question: best way to handle global data

Todd O'Bryan toddobryan at gmail.com
Thu Dec 6 22:42:21 GMT 2007


I'd probably use a class variable (aka a static variable) to hold it.
If it's public, then anybody can access or change it, if necessary. If
you think about it, System.out and System.err are exactly that.

Todd

On Dec 6, 2007 3:51 PM, Aryeh M. Friedman <aryeh.friedman at gmail.com> wrote:
> Let's say I have a global piece of data (like system wide configs) and
> need to make it aviable in a number of unpredictable situations (i.e.
> the caller does not necessarly know that global data will be used)....
> for example if I am writing a replacement for JUnit and have a setting
> for say the type of test and an other for say the reporting format to
> use for results... what is the best way to handle this... I can think
> two solutions use a Singleton (i.e. a class that has a static instance
> of itself and uses that static instance for all method calls) and the
> other is to pass the global data as a param... the con of the 1st is it
> violates the spirit of the no global data precept of OO and the draw
> back of the second is the caller needs to be (unnecessarily) aware of
> the fact that a called method will need global data.
>
> --
> Aryeh M. Friedman
> FloSoft Systems
> Developer, not business, friendly
> http://www.flosoft-systems.com
>
> _______________________________________________
> mailing list bluej-discuss at bluej.org
> To unsubscribe or change your preferences, go to
> http://lists.bluej.org/mailman/listinfo/bluej-discuss
>


More information about the bluej-discuss mailing list