🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #7700

Singleton Pattern: Use All Static Methods or Private Constructor?

#7700
From: Jack Frosch
Date: Mon, 28 May 2001 16:56
22 lines
1777 bytes
IN their book "Design Patterns" the GoF defines the Singleton pattern's
intent thus: "To ensure a class has only one instance, and provide a global
point of access to it."

For Java implementations, I've seen two implementation variations to achieve
this:

1) Some people code all static methods and data in a class, thus ensuring
only one "instance" of the class exists in the VM.

2) Others use an implementation where the class is defines as normal, but
with a private constructor.  A single public, static method is provided to
the single instance of the class that's stored as a private instance
variable.

Approach #2 clearly meets the pattern description of the GoF, but I'm
wondering if there are any uniquely-Java reasons why approach #1 might be
preferable?

Thanks.

Jack
Technical Details
Message-ID: <3b128359$1_1@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!news-xfer.nuri.net!enews.sgi.com!newsxfer.eecs.umich.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-was.dfn.de!news-koe1.dfn.de!RRZ.Uni-Koeln.DE!nntp.CS.Uni-Magdeburg.De!PeerFeed.KWeb.on.ca!dnews

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,604521ee4b628609,start
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-05-28 10:16:11 PST
From: "Jack Frosch" <jackfrosch[NO SPAM]@mail.com>
Newsgroups: borland.public.jbuilder.java.language
Subject: Singleton Pattern: Use All Static Methods or Private Constructor?
Date: Mon, 28 May 2001 11:56:03 -0500
Lines: 24
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 65.64.149.49
Message-ID: <3b128359$1_1@dnews>
X-Trace: dnews 991069017 65.64.149.49 (28 May 2001 09:56:57 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-03!supernews.com!news-xfer.nuri.net!enews.sgi.com!newsxfer.eecs.umich.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-was.dfn.de!news-koe1.dfn.de!RRZ.Uni-Koeln.DE!nntp.CS.Uni-Magdeburg.De!PeerFeed.KWeb.on.ca!dnews