Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7125

Re: Singleton Pattern

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Singleton Pattern
Date Mon, 15 Aug 2011 07:56:15 -0700 (PDT)
Organization http://groups.google.com
Lines 21
Message-ID <d490d89a-2e63-4099-9629-c275f2cf9847@glegroupsg2000goo.googlegroups.com> (permalink)
References <3be6e6cf-fa32-4503-9457-b0a1caef8f29@w11g2000vbp.googlegroups.com> <vt-dnf5wc8CJkdrTnZ2dnUVZ_jKdnZ2d@posted.palinacquisition> <j2b8q2$6pq$1@dont-email.me>
Reply-To comp.lang.java.programmer@googlegroups.com
NNTP-Posting-Host 172.19.63.59
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1313420176 26255 127.0.0.1 (15 Aug 2011 14:56:16 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Mon, 15 Aug 2011 14:56:16 +0000 (UTC)
In-Reply-To <j2b8q2$6pq$1@dont-email.me>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=172.19.63.59; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
User-Agent G2/1.0
X-Google-Web-Client true
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7125

Show key headers only | View raw


Ian wrote:
> Peter Duniho wrote:
>> I'd never even heard of the "single-element enum type" variation of
>> singleton initialization. That one in particular sounds like a
>> completely over-engineered approach.
>>
> I wouldn't say over-engineered - it's about as verbose as a final field 
> declaration.  ISTR one of the actual advantages is safety in the 
> presence of serialization, although Bloch mentions others . . .
> I'd say it's the right tool for the job of creating instance-controlled 
> data safely.
> [FX: Ducks!]

Actually, pretty much any attempt to lazy initialize is over-engineering.  Just declare a final member in most cases - why be lazy?  It's a false optimization.

Final fields, especially immutable ones, make a lot of useful guarantees, and you don't have the field in the first place unless it's going to be used at some point anyway.  Just freaking initialize it!

(I know, the enum pattern for final fields is not about lazy instantiation, although you do get that for free from it.  I have no issue with that pattern and use it myself.)

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Singleton Pattern "vbhavsar@gmail.com" <vbhavsar@gmail.com> - 2011-08-13 13:56 -0700
  Re: Singleton Pattern markspace <-@.> - 2011-08-13 14:41 -0700
  Re: Singleton Pattern Patricia Shanahan <pats@acm.org> - 2011-08-13 14:48 -0700
  Re: Singleton Pattern Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-13 16:43 -0700
    Re: Singleton Pattern Ian <m4r35n357@gmail.com> - 2011-08-15 15:00 +0100
      Re: Singleton Pattern Lew <lewbloch@gmail.com> - 2011-08-15 07:56 -0700
        Re: Singleton Pattern Patricia Shanahan <pats@acm.org> - 2011-08-15 22:07 -0700
          Re: Singleton Pattern Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-16 00:09 -0700
            Re: Singleton Pattern Patricia Shanahan <pats@acm.org> - 2011-08-16 06:15 -0700
              Re: Singleton Pattern Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-16 06:57 -0700
                Re: Singleton Pattern Patricia Shanahan <pats@acm.org> - 2011-08-16 09:25 -0700
                Re: Singleton Pattern Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-16 18:10 -0700
  Re: Singleton Pattern Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-13 20:56 -0400
    Re: Singleton Pattern Lew <lewbloch@gmail.com> - 2011-08-13 21:12 -0700
  Re: Singleton Pattern Rajeev <rajeev.nospam@gmail.com> - 2011-08-14 06:37 -0700

csiph-web