I have created an singleton class, this class returns a database connection. So my question is this connection is also satisfying singleton criteria?
If no, than how I can make it singleton.
Here is the code.
public sealed class SingletonDB
{
static readonly SingletonDB instance = new SingletonDB();
static SqlConnection con =new...
I've read the questions on S.O. regarding Singleton and just watched an hour long google tech talk. As far as I can tell, the consensus in the OO world seems to be that singletons are more of an anti-pattern rather than a useful design pattern.
That said, I am interviewing these days and the question comes up a lot--what is a singleton...
I have a fairly large CRUD WinForm app that has numerous objects. Person, Enrollment, Plan, CaseNote etc. There are over 30 forms that make up the app with the UI broken down logically. Member, Enrollments, Plans, CaseNotes, etc.
I am trying to figure out how I can create my Person Object after searching on the Search Form and pass ...
I have a singleton class for global access to config information. This singleton class called ConfigurationData extends EventDispatcher. Here is the class (note that I left some things out like variable declarations to keep this short):
/**
* Dispatched when the config file has been loaded.
*/
[Event (name="configurationLoaded", type=...
Duplicate
What’s wrong with singleton?
Singletons: good design or a crutch?
Singleton: How should it be used
What is so bad about Singletons
You can find numerous reasons for using a Singleton over a Static class. But there must surely be some situations where it is better to use a static class before a Singleton. What ar...
I'm building a web application using Stripes and Spring. It needs to have a login/authentication feature. Right now I store user information separate from user credentials in the database. My User model does not contain the credentials as I don't want to be passing around valuable passwords.
Spring manages all of my DAO's.
Now, I ...
I have a singleton class which needs to be intialized by castle? I'm a little newbie in castle. I have looked for singleton in castle and I saw setting the lifestyle attribute of component to "Singleton" seems enough. But in that case it seems I don't need to implement the class in "Singleton Pattern". Just plain class definition for my ...
I have some classes that are used as Singletons. They share some basic functionality and extend the same ancestor from a library which in turn isn't normally used as a Singleton.
If I put the common functionality in a base class that inherits from the common ancestor, I get a class which makes no sense to instantiate, so I made it abstr...
Hello,
I'm implementing a notification framework for one of my projects. As i want it to be very generic, the user can use several transport layers, so that he doesn't really need to care about using one delivery method (lets say WCF) or another (for eg ActiveMQ).
The interface the user has access is of course independent of the deliver...
Hi,
Im pretty new to objective-c programming and releasing of objects is my greatest headache.
I'm always doubting on what need to be released, and my times I've end up releasing the wrong variable and getting a BAD EXEC crash.
I've read apple's guide on memory management, but I cant always go from their examples to my code.
One of the...
Hi all,
On page 175, there is an example of Chocolate Boiler class. Something like this:
public class ChocolateBoiler {
private boolean empty;
private boolean boiled;
public ChocolateBoiler {
empty = true;
boiled = false;
}
// and then three methods to fill, drain and boil which changes the
// status...
I have read multiple articles about why singletons are bad.
I know it has few uses like logging but what about initalizing and deinitializing.
Are there any problems doing that?
I have a scripting engine that I need to bind on startup to a library.
Libraries don't have main() so what should I use?
Regular functions or a Singleton.
Can th...
The following concerns an iPhone app.
I want to use a singleton to handle an asynchronous URL request. I've got that covered but what is the best coding practice way to tell the singleton where to send the response when it is received? I need the response to be returned to the class which originally called the singleton.
Could I pass a...
We have a remoted singleton object hosted in IIS which is servicing multiple clients. During development we noticed that if one client is stopped in the debugger all other connected clients will stop receiving messages from the server. Messages are delivered via event call backs, the server will create it's own threads to send messages...
Ok, the question might not be crystal clear. Let me give some details:
Let's say I have an Shoe (CShoe) object factory class called CFactory.
CFactory is a singleton class that creates and stores all instanciated shoes using a simple hashmap. It is then accessed through static methods to use the created objects.
Is there a way to force...
In C++, I understand that it is possible to create a Singleton base class using templates. It is described in the book, Modern C++ Design, by Andrei Alexandrescu.
Can something like this be achieved in Java?
...
I'm storing my model data in a Singleton called ModelLocator. This is pretty common...
Can I look at this data in the debugger?
[Edited - Title changed]
...
One of the libraries we are using for our product uses a singleton for access to it. I'm pretty sure it's implemented as a static instance (it isn't open source). This works well for a single document application, but our app may have more than one document loaded. I'm assuming access to the instance is written something like this:
Inst...
How do I implement the singleton pattern in C# and ensure that it is thread safe?
...
I'm using component from a third party. The component provide a singleton pattern for context into our application. I'm using on my side this singleton but I would like to mock this object for my test. Is there any way to accomplish a mock on this object.
Also, the constructor is declared private.
...