Article View: borland.public.jbuilder.java.language
Article #15634limmiting the number of instances in java
From: Omer Azhar Qureshi
Date: Tue, 18 May 1999 00:00
Date: Tue, 18 May 1999 00:00
35 lines
1299 bytes
1299 bytes
hi ppl,
ive got a problem at hand at the moment that i want to limit the number of
objects that a class creates, i know that this is possible in C++ like
this.... also possible in smalltalk
class Singleton
{
public:
static Singleton * Instance ();
protected:
Singleton ();
private:
static Singleton* _instance;
};
Singleton * Singleton::_instance = 0;
Singleton* Singleton::Instance ()
{
if (_instance == 0)
{
_instance = new Singleton;
}
return _instance;
}
P.S. this example is from Design & Patrens by E. Gamma, R. Helm, R. Johnson
& J. Vlissides
but this dosent seem to work with java....
dose any1 have any idea how to achieve this in java....
thanx in advance
regards
Oaq
Technical Details
Message-ID:
<7hr7ck$bif3@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,88037c7ffe1531f,start X-Google-Attributes: gidf74b3,public From: "Omer Azhar Qureshi" <oaq@systemeltd.com.pk> Subject: limmiting the number of instances in java Date: 1999/05/18 Message-ID: <7hr7ck$bif3@forums.borland.com> X-Deja-AN: 479347691 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.0810.800 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.language