package mypackage;

public class Global // use this class to keep your global properties
{
    private Global() // disable it's constructor, since all its members are
static
    {
    }

    static // This is the static initialization. It is performed after the
class is loaded into jvm
    {
        res = new MyResource();
        // other init stuff
    }

    private static MyResource res;
    public static MyResource getRes()
    {
        return res;
    }
}

Then just import the Global class wherever you need it, and access resources
with Global.getRes(), i.e.

----- Original Message -----
From: Robert Simmons Jr. <[EMAIL PROTECTED]>
To: Java <[EMAIL PROTECTED]>
Sent: Wednesday, October 13, 1999 1:31 PM
Subject: A Global instance ?


> I have a gizmo that keeps track of resources for a program. The problem
> is that Im ending up passing this gizmo to every child component and
> that is beginning to bug me. In C++ I ould just create a global static
> var and let everyone access it. This is one of those rare cases where
> its a good idea. ALL parts use the same instance and the instance is
> read once (at the beginning) and written once(at program shutdown)
> anyone have any more elgant solution then passing it all over the damn
> place ?
>
> --rob
>
>
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact
[EMAIL PROTECTED]


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to