Article View: borland.public.jbuilder.java.language
Article #15635Re: limmiting the number of instances in java
From: Tor Iver Wilhelmsen
Date: Tue, 18 May 1999 00:00
Date: Tue, 18 May 1999 00:00
29 lines
1066 bytes
1066 bytes
"Omer Azhar Qureshi" <oaq@systemeltd.com.pk> writes:
> class Singleton
> {
> public:
> static Singleton * Instance ();
> protected:
> Singleton ();
> private:
> static Singleton* _instance;
>
> };
public class Singleton {
protected Singleton() { }
private Singleton _inst = null;
public static Instance() {
if (_inst == null)
_inst = new Singleton();
return _inst;
}
}
Note: The use of static means you need a separate Instance() for each
subclass - you could use a Factory instead if you like.
Technical Details
Message-ID:
<uiu9qkcis.fsf@sds.no>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7hr7ck$bif3@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,88037c7ffe1531f X-Google-Attributes: gidf74b3,public From: Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no> Subject: Re: limmiting the number of instances in java Date: 1999/05/18 Message-ID: <uiu9qkcis.fsf@sds.no> X-Deja-AN: 479350336 Sender: towi@SDSA1761 References: <7hr7ck$bif3@forums.borland.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language