I know that Singleton pattern is bad because it uses global state. But in most applications, you need to have a single instance of a class, like a database connection.
So I designed my Database object without using the singleton pattern but I instanciate it only once.
My question is, how can I access my object in the low level classes ...
Hello,
for a while I wonder if it is a good idea to store some data in a singleton when writing a web-(or WCF)service. The goal is to reuse this information in different calls of the service.
I wonder what's the lifetime of those singletons, because for example when the application pool is recycled, the singleton is gone.
Next Question ...
I have a MySQL singleton class written in PHP. Its code is listed below:
class Database {
private $_result = NULL;
private $_link = NULL;
private $_config = array();
private static $_instance = NULL;
// Return singleton instance of MySQL class
public static function getInstance(array $config = array()) {
...
namespace AV.Connections
{
protected class MyConnection
{
protected ConnectionStringSettings connectionSettings
{
get { return ConfigurationManager.ConnectionStrings["mySQLConnection"]; }
}
protected DbConnection connection
{
get { return new OdbcConnection(co...
I have a C++ singleton that runs as a separate thread. This singleton is derived from a base class provided by a library and it overrides the method onLogon(...). The onLogon method is synchronous, it wants to know right away if we accept the logon attempt.
Problem is we need to pass the logon information via message to a security ser...
Hello, I have a singleton timer in my WP7 application however I have no idea how to get it to update a textblock everytime the timer ticks... Is there a way to get the event handler of the timer ticking and then update the textbox with the correct time?
Here is what I tried to use but wouldn't work:
public _1()
{
Initializ...
I was looking through some code in a string escape library the other day and I came across some code that looks like this:
class StringWrapper
class << self
alias new_no_dup new
def new(str)
new_no_dup(str.dup)
end
end
def initialize(str)
@str = str
end
...
end
Can anyone explain exactly what is goi...
Good morning,
I would like to have an eager singleton in Unity, this singleton needs to be injected into so the RegisterInstance methods alone would not do it. The only other thing I can think of is in the configuration module have something like:
container.RegisterType<Singletion, Singletion>(new ContainerControlledLigetimeManager(...
Hello,
I am working on an application with a GUI using wxWidgets. I got an object used as a "model": its data has to be used to draw the ui and the ui should modify it. Let's call this class Model.
The structure of the applications looks like this:
A wxApp-derived object, that possesses:
a wxFrame-derived object, that possesses a
wx...
I got a requirement in my project to add another property to some class.
Now I want to avoid changing the class because I figured it shouldn't be aware that he has this property (this property only has significance in the context of this project).
The way I thought to accomplish this was (Please critic this because I wanna know if there...
If I have a database.php class (singleton) which reads and writes information for users of my web application, what happens when simultaneous requests for the same database function is called?
Is it possible that the database class will return the wrong information to other users accessing the same function at the same time?
What othe...
Hello,
I have this code:
class MyController {
public function newUserAction()
{
$view = new View('myfrontend');
if($this->request->isPost())
{
$form = new MyForm;
$posts = $this->request->getPosts();
if($form->isValid($posts))
{
//...
}
}
$view->display();
}
}
S...
Possible Duplicates:
Singletons: good design or a crutch?
Problems with Singleton Pattern
Singleton: How should it be used
Hi..
Please help me up to understand what is the use of singleton class
Thank you
...
If an Activity is a singleton in practice, I think I can gain some efficiency by declaring appropriate members "static", with zero risk. Yes?
...
I have a singleton class AppSetting in an ASP.NET app where I need to check a value and optionally update it. I know I need to use a locking mechanism to prevent multi-threading issues, but can someone verify that the following is a valid approach?
private static void ValidateEncryptionKey()
{
if (AppSetting.Instance.EncryptionKey.Equ...
Hello,
I have a singleton in an activity. When I end my application (like pressing back button), and start it again after some time, the singleton is not recreated, but is holding previous state. Singleton is not destroyed if the application is destroyed? Do I have to null its static members in onDestroy() to avoid memory leak?
Thanks.
...
In my code, I use a singleton object as a central point in my app to load and cache images the app frequently needs, so I don't have to do resource-intensive memory allocation each time I load an image.
But there are times during the execution of my app where memory usage gets intense and I would like to release the cached image data. C...
Hi all,
I'm interested in objective analysis of which is more performant; calling instance methods of a singleton class or methods of a static class. I've already seen this so I'm not looking for a discussion about the difference between the two or a discussion of which is "better." I'm only interested in relative performance between t...
Hi,
I needed to understand the design pattern(s) used in log4j library.
Since it provides loggers for various classes, it it a factory ?
Any more inputs/pointers on these is greatly appreciated..
...
Hi,
I had an interview recently and he asked me about Singleton Design Patterns about how are they implemented and I told him that using static variables and static methods we can implement Singleton Design Patterns.
He seems to be half satisfied with the answer but I want to know
How many different ways we can
implement Singleton...