Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.tele2net.at!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 05 Feb 2013 03:43:36 -0600 Date: Tue, 05 Feb 2013 09:43:33 +0000 From: lipska the kat <"nospam at neversurrender dot co dot uk"> Organization: Trollbusters 3 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120410 Thunderbird/11.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Design Patterns References: <3c0d69c3-591d-4d99-8c13-30a0fd1684b3@googlegroups.com> <68pyk4ua9x9m.1nm4lckdwgp86.dlg@40tude.net> <51106eff$0$293$14726298@news.sunsite.dk> <1g6plnhx9njxt$.bx5mrpbwc6mi$.dlg@40tude.net> In-Reply-To: <1g6plnhx9njxt$.bx5mrpbwc6mi$.dlg@40tude.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 70 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-GjwqobgKHp/e8xRdvx/DI4z2Qju9a/G+29LJKhzIGt4wFxRGYogzX+lLpNA5scEU2iBuVMQJxsu4dC3!0gXEdqyfpwZyBK50/24iGYmzi5Kcx8qS4tvwcKSZWKqxkAjumv4kzuIWp4z2EFOEPGPeBlq1GRM= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3815 Xref: csiph.com comp.lang.java.programmer:22110 On 05/02/13 05:03, Peter Duniho wrote: > On 5 Feb 2013 04:10:11 GMT, Stefan Ram wrote: > >> Arne Vajhøj writes: >>>> Pattern or anti-pattern, I never encountered a situation where I felt a >>>> need for »singletons«. >>> Other have. >> >> Maybe someone can come up with an SCSE where a singleton is needed. > > _Needed_ is situation-specific, but examples generally will include > situations where multiple callers require access to some shared resource > abstracted by the singleton class. In some cases, a static class suffices. > But in other cases it's either useful or required to have a singleton (e.g. > because you need the singleton to implement an interface, something static > classes in Java can't do). OK, I know I'm probably still being ignored because I've upset some people but can someone please explain to me exactly what a 'static class' is (WRT Java of course) This is illegal public static class Foo{... a class with all static methods certainly can implement an interface This compiles public class Foo implements Serializable{ public static void Bar(){ } } So what makes a class 'static enough' so that it can't implement an interface ? (for example) As for a Singleton Well some years ago I went for an interview The interviewer showed me the following line of code(or something like it) private final Integer var = 10; He asked me what I thought of it. I said it was a flag to future maintainers that this value was important and should not be changed without fully understanding the implications. I got the job (after lots more questions of course) And this is one reason I think I might use a singleton In a system with potentially many statics a Singleton (hopefully) stands out. It makes explicit the intentions of the developer. People who understand design patterns will understand what a Singleton is, if you like it's a form of documentation. As for an example (I think this has been mentioned before). I seem to remember back in the day writing a database connection pool manager as a Singleton. Why ? well it probably seemed like a good idea at the time :-) just my 2 euros worth lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun