Methods related to using of the singleton design pattern.
Questions tagged [singleton-methods]
76 questions
1
vote
1 answer
Throw error if exported module function is called twice
I have a Node.js module that exports a function:
module.exports = function(data){
return {
// return some object
}
};
I am looking to use a singleton pattern here, but without much extra fuss. This is for a library, and it's possible…

Alexander Mills
- 90,741
- 139
- 482
- 817
1
vote
1 answer
Thread-safely update a singleton's dependency via setter at runtime from scheduled job
I have a spring based java app and my goal is to cache a bunch of objects in memory for performance and use a scheduled job to update that cache from the data source periodically.
If I am storing that map in a singleton spring bean, is there a…

Nathan Hadzariga
- 342
- 3
- 16
1
vote
4 answers
How can I create a instance like objective-c do?
Usually, I create a class's instance like this:
The Parent class:
@interface baseClass
+ (instancetype)task;
@end
@implement baseClass
+ (instancetype)task {
return [[[self class] alloc] init];
}
@end
and then in children…

imeteora
- 13
- 4
1
vote
3 answers
What is the difference between Singleton Design Pattern and Singleton Object In Java?
This was the question that was asked to me recently in an interview.
According to me, it is through singleton pattern we can instantiate singleton objects. But, I would like to know whether I am right or not.

dgupta3091
- 1,067
- 1
- 7
- 18
1
vote
1 answer
Stateless Singletons and Concurrency
I have a question about stateless singletons. I also have a question about singletons with state.
Stateless singleton services are a good way to help with scalability. The programmer who architected the project which I maintain basically said…

onefootswill
- 3,707
- 6
- 47
- 101
1
vote
1 answer
Collections.singleton() methods does not work as documentation?
I have tested Collections.singleton() method, how to work, but i see that it is not work as what documentation say?
List arraylist= new ArrayList();
arraylist.add("Nguyen");
arraylist.add("Van");
arraylist.add("Jone");
List list =…

Quan Nguyen
- 698
- 1
- 9
- 19
1
vote
2 answers
Android: Is it possible to share a GoogleApiClient between activities and services?
Do every activity and service have to create their own GoogleApiClient and manage it with their onPause, onStop and connectivity issues? Is it possible to make an app client?
What I'm doing now is to copy and paste the same code in every activity or…

user3290180
- 4,260
- 9
- 42
- 77
1
vote
0 answers
Passing in a pointer into a static library to be used in all classes?
What is the appropriate way to accept a pointer to a class that is subsequently used within a static library across all objects within that library?
The classic case is a logger, which I will use as an example here.
Singletons are often used…

user3072517
- 513
- 1
- 7
- 21
1
vote
2 answers
On multiple Class#extend calls
Consider a code from this article:
class Coffee
def cost
2
end
end
module Milk
def cost
super + 0.4
end
end
module Sugar
def cost
super + 0.2
end
end
coffee = Coffee.new
coffee.extend(Milk)
coffee.extend(Sugar)
coffee.cost…

Andrey Esperanza
- 625
- 1
- 6
- 11
1
vote
3 answers
Android application creation of internal file that isn't in an activity
I am trying to create an internal file in an android application. I have generated the code that works fine with java, but in order to create the internal file I believe I must have the context to do so.
Example: File file = new…

blackexile
- 13
- 4
1
vote
1 answer
Concurrent processing via scala singleton object
I'm trying to build a simple orchestration engine in a functional test like the following:
object Engine {
def orchestrate(apiSequence : Seq[Any]) {
val execUnitList = getExecutionUnits(apiSequence) // build a specific list
…

BSJ
- 1,185
- 2
- 10
- 15
1
vote
2 answers
How can a class call a class method that is defined on a singleton class?
I continue my study on Ruby and another question occurred me. I know that when we define a class method on a class, it's created a singleton class that gets the definition of that method, and from then on, that method is an instance method of that…

BrunoMCBraga
- 652
- 2
- 7
- 23
1
vote
1 answer
Singleton set in AppDelegate loses it value when allocated in another class
I have a iPad application where I'm attempting to use a singleton. This is the code in the .h file:
//-------------------------------------------
//-- singleton: timeFormat
@interface SingletonTimeFormat : NSObject {
}
@property (nonatomic,…

SpokaneDude
- 4,856
- 13
- 64
- 120
1
vote
1 answer
How may I change value of a global variable using singleton class method?
I would like to be able to call a method from any class which changes the value of my global variable.
I'll first outline the problem for anyone who doesn't wish to view the code.
Apologies in advance for the long post! I just want all the details…

Mish
- 31
- 6
1
vote
1 answer
Converting phpUri call into CI Library call
Code in native PHP:
$href = phpUri::parse($target_url)->join($href);
Code I tried in CI which is not working:
$CI->load->library('Phpuri', array($target_url));
$href = $CI->phpuri->parse($target_url);
$href = $CI->phpuri->join($href);
You can see…

SilentAssassin
- 468
- 1
- 9
- 27