473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Singleton Pattern or Rubbish?

Somehow I got lost in an article that led me here:

http://www.javascriptkata.com/2007/0...e-a-singleton/

Having recently seen someone else mentioning a Singleton pattern in JavaScript, I wonder,
like the commenter Aaron, why anyone would use one?

For anyone who doesn't know what a Singleton pattern is, look here:

http://en.wikipedia.org/wiki/Singleton_pattern

"the singleton pattern is a design pattern that is used to restrict instantiation of a
class to one object"

Which basically means we end up with an object that has the ability to restrict itself to
only one instance at a time.

Anyway, I would appreciate any *clear* examples of how one might *require* a Singleton
pattern.

-Lost
Apr 8 '07 #1
2 1468
-Lost wrote:
Somehow I got lost in an article that led me here:

http://www.javascriptkata.com/2007/0...e-a-singleton/

Having recently seen someone else mentioning a Singleton pattern in JavaScript, I wonder,
like the commenter Aaron, why anyone would use one?
JavaScript can support much simpler formulations. For example:

var catNames = function () {
var names = [];
return {
add: function (catName) {
names.push(catName);
},
removeLast: function () {
return names.pop();
},
alertAllCats: function () {
alert(names.join(","));
}
};
}();

http://javascript.crockford.com/
Apr 8 '07 #2

-Lost wrote:
Somehow I got lost in an article that led me here:

http://www.javascriptkata.com/2007/0...e-a-singleton/

Having recently seen someone else mentioning a Singleton pattern in JavaScript, I wonder,
like the commenter Aaron, why anyone would use one?
..........................
Anyway, I would appreciate any *clear* examples of how one might *require* a Singleton
pattern.
http://prototyp.ical.ly/index.php/20...the-singleton/

Apr 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alicia Roberts | last post by:
Hello everyone, I have been researching the Singleton Pattern. Since the singleton pattern uses a private constructor which in turn reduces extendability, if you make the Singleton Polymorphic...
1
by: Richard A. DeVenezia | last post by:
foo() generates elements with event handlers that invoke foo function properties. Is this an abhorrent or misthought pattern ? It allows just the one occurence of identifier /foo/ to be changed...
3
by: Alicia Roberts | last post by:
Hello everyone, I have been researching the Singleton Pattern. Since the singleton pattern uses a private constructor which in turn reduces extendability, if you make the Singleton Polymorphic...
11
by: Daniel Billingsley | last post by:
Let's say I'm writing a business app and I want there to be only one instance of the Customer object for each particular customer (representing a database record) being edited. Would it be...
21
by: Sharon | last post by:
I wish to build a framework for our developers that will include a singleton pattern. But it can not be a base class because it has a private constructor and therefore can be inherit. I thought...
13
by: Robert W. | last post by:
At the beginning of my C# days (about 6 months ago) I learned about the Singleton pattern and implemented for Reference data, such as the kind that appears in an Options dialog box. My Singleton...
2
by: Kevin Newman | last post by:
I have been playing around with a couple of ways to add inheritance to a JavaScript singleton pattern. As far as I'm aware, using an anonymous constructor to create a singleton does not allow any...
3
by: dischdennis | last post by:
Hello List, I would like to make a singleton class in python 2.4.3, I found this pattern in the web: class Singleton: __single = None def __init__( self ): if Singleton.__single: raise...
3
weaknessforcats
by: weaknessforcats | last post by:
Design Pattern: The Singleton Overview Use the Singleton Design Pattern when you want to have only one instance of a class. This single instance must have a single global point of access. That...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.