Hi. Let's say I want to use an EJB container and I don't know how the container implementation is using classloaders.
Now, I want to have in-memory shared state with my custom datastructures (so no HSQLDB etc.). in this app., and the EJB spec happens to be < EJB 3.1 and I can't use the EJB singleton service.
If I'd use DI frameworks...
Hey all
I've recently implemented a singleton class, and within it I've declared a static generic list of (T) class. Anyway this is my first attempt at using singleton but everything I've tried work so far.
My Question: To be consistent, I don't want the MasterSiteData to be visible to other classes except my Singleton class. I thought...
Hi,
In a recent project I had to create a Singleton class and after a lot of digging around on Google I came up with this template class definition. The idea is to derive from this template class and make the derived class' constructor protected / private. It seems to work well but I have only used it with a single class in one project ...
Hi
was thinking about creating a Single class called 'Request' to handle and clean POST and GET variables but being new to the singleton pattern I'm not sure how to implement it. Ideally I'd like to have 2 functions post($name,$clean) and get($name,$clean) - $clean being a boolean to determine whether to trim/ escape the value
...
I am declaring a Spring bean for a Java class that is used as a factory to create objects. I want to use this factory from different threads, the problem I am experienced is that threads are blocked when they try to create an object using the factory.
As far as I know spring beans are singletons by default, and this is what I want. I wa...
There are a lot of questions out there about whether singletons are "bad," and what patterns to use instead. They're generally focused on the singleton design pattern, which involves retrieving the singleton instance from a static method on the class. This is not one of those questions.
Ever since I really "discovered" dependency inject...
It would be nice if StackOverflow had a section where we could post tutorials like mine so that I can answer literally hundreds of questions that have been asked here with a single blow. See... every day I read questions about how to pass complex objects between activities, how to save state so that your app can resume after orientation ...
Hi:
I have a Main class loading 2 SWF (loader and viewer, also with document classes). They need to share a double buffer with content, of course, filled by loader and showed by viewer
I was thinking to use the LocalConnection class but after a suggestion from PatrickS now I'm evaluating the possibility of a Singleton Class. I've never...
Hi guys:
I have four classes, let's call S1, S2, S3 and S4. These class are singletons; each one have a getInstance and a finalize method - and an instance private variable-.
Now, to avoid repeting the finalize and getInstance methods I'm trying to make a SingletonMixin class, something like:
template<class T> class SingletonMixin
{
...
Given the following:
module MyModule =
let myObj = new MyObj()
type MyType() =
static let myObj_ = new MyObj()
static member myObj = myObj_
... are MyModule.myObj and MyType.myObj functionally (no pun intended) equivalent?
Whenever I call MyModule.myObj or MyType.myObj, I don't want the code to actually create a new obje...
Anything wrong with the following Singleton implementation?
Foo& Instance() {
if (foo) {
return *foo;
}
else {
scoped_lock lock(mutex);
if (foo) {
return *foo;
}
else {
// Don't do foo = new Foo;
// because that line *may* be a 2-step
/...
I have an application that has several classes used for storing application-wide settings (locations of resources, user settings, and such). Right now these classes are just full of static fields and methods, but I never instantiate them.
Someone suggested I make them Singletons, What's the case for/against?
...
I'm adapting Image Downloader from Google Android blog. I want ImageDownloader to be singleton since I'll be using it in multiple places in my application. I want also to be able to manipulate Bitmaps using different Strategies (eg. produce transparent bitmaps).
Context:
I want to be able to use ImageDownloader in one activity and set ...
I'm using Visual Studio 2010 to write a simple C#/.NET GUI app, wherein I use a Logger class to write tracing/debugging info to a single file from within all of the various classes of the project. (See source code below.)
Each class's constructor writes an entry to the log when one of its object types is instantiated. One of those class...
Hi,
I'd like to expose some functionality via a WCF service. I can configure WCF to instantiate a class per-request but am unsure how I can get a reference to a communal singleton -
If I were to have some functionality to store a list of calls to a method (call it LogMethod) via WCF in memory and return that list when the GetLogs meth...
I am writing an iPhone app and I want to create a NSCache singleton.
I am having trouble, here's the code that I have:
MyAppCache.h:
#import <Foundation/Foundation.h>
@interface MyAppCache : NSCache {}
+ (MyAppCache *) sharedCache;
@end
MyAppCache.m:
#import "SpotmoCache.h"
static MyAppCache *sharedMyAppCache = nil;
@implement...
Hi,
I was reading around a lot about singleton. I am thinking about the dead reference problem between singletons. In every primer on net , this problem is encountered when one singleton calls other singleton in its destructor, and that singleton is already destroyed, say Log singleton can be called from destructor of many other singlet...
I want to define a Singleton base type from which the user will derive his classes, so this is what I thought:
interface SingletonInterface {
public static function getInstance();
}
abstract class SingletonAbstract implements SingletonInterface {
abstract protected function __construct();
final private function __clone() {...
In Scala I could define an abstract class and implement it with an object:
abstrac class Base {
def doSomething(x: Int): Int
}
object MySingletonAndLiteralObject extends Base {
override def doSomething(x: Int) = x*x
}
My concrete example in Python:
class Book(Resource):
path = "/book/{id}"
def get(request):
...
Let's say that I'm currently designing an application where I will need to use a global timing system (it's a cross-cutting concern). I'll need to access data from that global timing system from basically anywhere in my app and it's not like I can see that "this part of the application will need it while the other won't".
My question i...