Você está na página 1de 7

5/9/13

2 different types of singleton (Java in General forum at JavaRanch)

This week's book giveaway is in the HTML and JavaScript forum. We're giving away four copies of Early Release edition of Programming JavaScript Applications and have Eric Elliott online! See this thread for details.

Big Moose Saloon


A friendly place for programming greenhorns!
Search

Java FAQ

Recent Topics

Register / Login

Win a copy of Early Release Edition of Programming JavaScript Applications this week in the HTML and JavaScript forum!

JavaRanch Java Forums Java Java in General

Go

Author

2 different types of singleton


posted 7/17/2006 5:25 PM

Ilja Preuss author Sheriff Joined: Jul 11, 2001 Posts: 14112

Originally posted by Vj Kamath: The universe is a singleton. God is a singleton. "The One" as they like to call

With all due respect, the only singleton that is *not* off topic for all forums at JavaRanch but Meaningless Drivel is the Singleton design pattern as it is used in the patterns community. I think it would be good if we could restrict the discussion in this forum to the technical matters of the design pattern, and move the philosophical discussions - however interesting they are - to some more appropriate place. Thanks!

The soul is dyed the color of its thoughts. Think only on those things that are in line with
www.coderanch.com/forums/posts/list/40/380309 1/7

5/9/13

2 different types of singleton (Java in General forum at JavaRanch)

your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus Rusty Shackleford Ranch Hand Joined: Jan 03, 2006 Posts: 490

posted 7/18/2006 1:54 AM

PLEASE ,dont compare java, and computer fundamentals with physics,maths or any other scrap

You know there is a reason why a heavy load of physics and mathematics is required for computer science and computer engineering. Computer and programming language fundamentals is built on them.

"C omputer science is no more about computers than astronomy is about telescopes" Edsger Dijkstra

Joel McNary Bartender Joined: Aug 20, 2001 Posts: 1815

posted 7/20/2006 1:35 AM

This was a very interesting thread. The arguments presented by Mr. Morris are quite fascinating. However, as far as I know and as I have been taught, the Singleton design pattern does not require that there be a Single instance -- just a controlled number of instances. I myself have implemented Singleton patterns such that there is one instance per Thread. I also am in deep sympathy for Mr. Morris for his having to work on WebSphere. My deepest regrets.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.

Scott Selikoff Saloon Keeper Joined: Oct 23, 2005 Posts: 3652
I like...

posted 7/20/2006 1:36 AM

Originally posted by Tony Morris: C omputational progression requires time (and therefore space) in order to exist. The laws of the physics are what makes Java possible even if indirectly or not immediately obvious. I had already put the disclaimer in place anyway; the casual observer will not see the correlation. It simply isn't taught at school despite being of utmost importance (market pressures aside).

Yes, because market pressues hate when programmers are forced to understand that time and space exist, instead of taking it as a given; it really interferes with their timetables.
www.coderanch.com/forums/posts/list/40/380309 2/7

5/9/13

2 different types of singleton (Java in General forum at JavaRanch)

In fact, since you doubt the existence of language, classloaders, and pretty much everything having to do with programming, then I one-up you be claiming that languages itself do not exist since they are just concepts with no concrete explanation. The bits floating through the web that happen to make it on to the website are shear luck of atoms and energy. In fact, heck, I'm not even sure anyone outside the room I am in exists, I can't be sure therefore doubt wins and I must be a sole brain floating in a vat in the Texas. The robots won and we are all playing their game. You figured it out.

My Blog: Down Home C ountry C oding with Scott Selikoff

Naseem Khan Ranch Hand Joined: Apr 25, 2005 Posts: 809

posted 7/20/2006 2:24 AM

I think the definition given by Joel McNary is absolutely correct. Controlled number of instances rather than single instance. Single instance is a relative term. Important thing is who is the Observer. It could be Thread or class loader or even jvm. Naseem

Asking Smart Questions FAQ - How To Put Your C ode In C ode Tags

Ken Blair Ranch Hand Joined: Jul 15, 2003 Posts: 1078

posted 7/20/2006 2:42 AM

Originally posted by Naseem Khan: I think the definition given by Joel McNary is absolutely correct. C ontrolled number of instances rather than single instance. Single instance is a relative term. Important thing is who is the Observer. It could be Thread or class loader or even jvm. Naseem

He didn't give a definition. The GoF book I have in front of me says "single instance" not "a controlled number of instances". It's not really a relative term, it simply requires a context.

Naseem Khan Ranch Hand

posted 7/20/2006 2:52 AM


3/7

www.coderanch.com/forums/posts/list/40/380309

5/9/13

2 different types of singleton (Java in General forum at JavaRanch)

Joined: Apr 25, 2005 Posts: 809 Originally posted by Joel McNary However, as far as I know and as I have been taught, the Singleton design pattern does not require that there be a Single instance -- just a controlled number of instances. I myself have implemented Singleton patterns such that there is one instance per Thread.

Whatever you say relative or context? End result is same.

Naseem [ July 19, 2006: Message edited by: Naseem Khan ]

Tony Morris Ranch Hand Joined: Sep 24, 2003 Posts: 1608

posted 7/20/2006 4:16 AM

Originally posted by Scott Selikoff:

Yes, because market pressues hate when programmers are forced to understand that time and space exist, instead of taking it as a given; it really interferes with their timetables. In fact, since you doubt the existence of language, classloaders, and pretty much everything having to do with programming, then I one-up you be claiming that languages itself do not exist since they are just concepts with no concrete explanation. The bits floating through the web that happen to make it on to the website are shear luck of atoms and energy. In fact, heck, I'm not even sure anyone outside the room I am in exists, I can't be sure therefore doubt wins and I must be a sole brain floating in a vat in the Texas. The robots won and we are all playing their game. You figured it out.

The first paragraph is probably sarcasm but correct nonetheless. The second paragraph is a digression from anything related to this thread and anything I have said, so I can only respond with "wtf?". Perhaps you are confusing my assertion that "singletons do not exist until spacetime is shown to be finite" with something related to programming languages and/or class loaders. An alternative approach to the conclusion is to perform a thought experiment; conjecture some definition of "singleton", externalise it, expend effort attempting to derive some artifact which meets the aforementioned definition (it is quite easy for this case but I can help you out if you like) and then ask yourself if it is absurd to consider it a "singleton". If it does appear absurd, then conjecture a new definition for "singleton". If it doesn't appear absurd, repeat the process of deriving an artifact to meet the definition. If you have shifted your
www.coderanch.com/forums/posts/list/40/380309 4/7

5/9/13

2 different types of singleton (Java in General forum at JavaRanch)

definition, repeat the entire process. After you have repeated it 10 or so times, we might consider discussing whether or not the process is in fact infinite (I assert that it is). After which, we would conclude that no such thing exists as a formal definition - only relative to the observer (i.e. you and I can have two different but legitimate definitions). We have already seen three definitions on this thread: 1) Class loader scoped data (to which I provided an artifact that is class loader scoped data and it was denied to be a singleton). 2) The GoF definition 3) Instance scoped data (making the "single" in "singleton" meaningless) The third point has attached with it an extremely long discussion involving requirement analysis that I am most interested in, but concede to the fact that others may not or simply don't have the required background knowledge. Suffice to say that I haven't explicitly invoked a constructor in years - I have only ever declared an explicit constructor private and I also declare it to throw an exception at all times; I'll leave you to ponder that. There is a name for the above method of logic, but sound reasoning (aka logic, mathematics, philosophy) seems to scare a few people and appears unrelated to software (which might well be a valid point for a given definition of software) so perhaps we should just leave it all be.

Tony Morris Java Q&A (FAQ, Trivia) Steve L. Williams Greenhorn Joined: May 20, 2006 Posts: 13

posted 7/20/2006 4:59 AM

It is nice you claim that your often odd theories are proved mathematically. Problem is, I have yet to see you prove anything, just claim that it is proved.

Ken Blair Ranch Hand Joined: Jul 15, 2003 Posts: 1078

posted 7/20/2006 6:29 AM

Originally posted by Naseem Khan:

Whatever you say relative or context? End result is same.

Naseem [ July 19, 2006: Message edited by: Naseem Khan ]

Yeah, it probably is. I think I misinterpreted what you meant.

www.coderanch.com/forums/posts/list/40/380309

5/7

5/9/13

2 different types of singleton (Java in General forum at JavaRanch)

Tony Morris Ranch Hand Joined: Sep 24, 2003 Posts: 1608

posted 7/20/2006 8:15 AM

Originally posted by Steve L. Williams: It is nice you claim that your often odd theories are proved mathematically. Problem is, I have yet to see you prove anything, just claim that it is proved.

I assume this is addressed to me given the usual (from the Java community) adjective 'odd', which I reject, but I'll ignore it anyway. I have not claimed to have proven anything, not mathematically, not at all. However, I have claimed that the notion of a singleton has not been proven to exist. I have asked for a reasonably formal definition a couple of times - not for any other reason than I know that nobody will provide me with one (since it does not exist) and this is the 50th post on this thread, so I could continue ad infinitum or call it a day at 50. I'm proposing the latter.

Stefan Wagner Ranch Hand Joined: Jun 02, 2003 Posts: 1923
I like...

posted 7/20/2006 9:27 AM

Multiton is mentioned at wikipedia: "Multiton is a (disputed) term often used to describe a Singleton-like pattern that allows more than just one instance to be created." I can imagine Dualton, Tripliton, Dozenton and Gigaton too. Of course we should get the Singleton right, before discussing the Dualton.

http://home.arcor.de/hirnstrom/bewerbung Ernest Friedman-Hill author and iconoclast Marshal Joined: Jul 08, 2003 Posts: 24032

posted 7/20/2006 9:30 AM

Tony's got it right. Since this thread long ago left the path of righteousness, it's time to close it. Good night, and good luck.

13
I like...

[Jess in Action][AskingGoodQuestions]

I agree. Here's the link: http://aspose.com/file-tools

www.coderanch.com/forums/posts/list/40/380309

6/7

5/9/13

2 different types of singleton (Java in General forum at JavaRanch)

subject: 2 different types of singleton

Similar Threads Combining State and Singleton design patterns Should the Singleton instance be a final variable? singleton class doubt about MasterExam question Singleton
All times above are in your local time zone & format.T he current ranch time (not your local time) is May 08, 2013 21:24:50 .

Contact Us | Powered by JForum |

C opyright 1998-2013 Paul W he aton

www.coderanch.com/forums/posts/list/40/380309

7/7

Você também pode gostar