Methods related to using of the singleton design pattern.
Questions tagged [singleton-methods]
76 questions
0
votes
1 answer
Android:How to make all activity can use socket connections
I had to establish a socket in ActivityA in normal and ready to send data,
but now I want to also be able to use the same socket connection to transmit the data in ActivityB.I have looked for information on the Internet, it seems can use the…

Shane Jhan
- 5
- 7
0
votes
3 answers
Confusion regarding how to use a NSMutableArray and Singleton
I am experimenting using a singleton for the first time. I would like to have an array that is global to all my view controllers with some special methods to add and remove items (this is for a shopping cart kind of thing).
My singleton class is…

May Yang
- 523
- 1
- 5
- 18
0
votes
1 answer
How to pass a singleton object to a partial in rails?
I have the following code in my controller
@current_chat = current_user.sent_messages
.where("created_at > ? and receiver_id = ?", current_user.current_sign_in_at, current_chat[:receiver_id].to_i)
…

Akshay Takkar
- 500
- 1
- 7
- 21
0
votes
1 answer
constructor is private error using singleton c++ and within this context error
i am following SDL game development book by shaun mitcchel and was trying to compile the code and was getting error of constructor is private. i am using mingw for compiling.
main.cpp
#include "game.h"
game* g_game = 0;
int main(int argc, char*…

Gautam Chandna
- 13
- 1
- 7
0
votes
3 answers
what does a singleton method belong to if the metaclass method is wrongly overridden?
In the "rubymonk" and some other ruby resources, it is mentioned that when you define a singleton method on an object, under the hood, Ruby is adding this new method to the object's metaclass. right? and also there is a trick to access the metaclass…

Pooya
- 992
- 2
- 10
- 31
0
votes
2 answers
Ruby: How do I refactor code from two module class methods?
Here's the code:
module A
class C1
def self.grovel(x)
return A::helper(x) + 3
end
end
class C2
def self.grovel(x)
return A::helper(x) + 12
end
end
private
def helper(y)
y + 7
end
module_function…

Eric
- 2,115
- 2
- 20
- 29
0
votes
2 answers
Spring MVC Singleton Controller - Multiple Download Requests
I'm aware that Spring MVC controllers are Singletons.
So, using the controller's fields to store data can result into security issues.
What by question is, suppose it have a mapping which allows users to download a file -
@RequestMapping(value =…

kaustav datta
- 687
- 2
- 11
- 31
0
votes
1 answer
How to share variable between all instances of worker process asp.net
I had To move a pre built asp website from single worker process environment to multiple worker process environment on cloud servers.
I was having a class with static arraylist variable which use to contain last 2 minutes of all session information…

Ratna
- 2,289
- 3
- 26
- 50
0
votes
8 answers
How to extend a singleton class to handle a specific number of objects
In Java, I have created a singleton class as follows:
public class Singleton
{
private Singleton() { print("Singleton Constructor"); }
private static Singleton pointer = new Singleton();//static here so only one object
public static…

Shashi
- 746
- 10
- 39
0
votes
1 answer
"[[self sharedManager] retain]" why should retain
In apple doc singleton:
static MyGizmoClass *sharedGizmoManager = nil;
+ (MyGizmoClass*)sharedManager {
if (sharedGizmoManager == nil) {
sharedGizmoManager = [[super allocWithZone:NULL] init];
}
return sharedGizmoManager;
}
+…

user2412433
- 11
0
votes
3 answers
singletons and threads
My question is about threads being queued. For my example I have one Spring context. I have a method named CalculateTax in a stateless class. A request comes in, a thread is created (tA) and it eventually enters the CalculateTax method. Within the…

user195166
- 417
- 5
- 16
0
votes
1 answer
Objective-C macros - calling a singleton object's method
I'm working with a singleton object/class, and need to call one of its methods frequently, and from many places in a large project. I need define a macro to handle this, but it's not working at the moment. This needs to handle a variable argument…

mayonaise
- 129
- 2
- 12
0
votes
1 answer
Singleton Design Implementation
As per my previous question, here, I've adapted my Data Controller class over to use a singleton design pattern so that I can use it only once across multiple views. However I do have a couple question I can't seem to find the solution too.
Firstly…

Flatlyn
- 2,040
- 6
- 40
- 69
-1
votes
1 answer
How to make a user defined method in main viewcontroller that updates values continuously in iOS?
I learned objective c myself and haven't taken any courses for it. Hence, some times I get confused with minor things while writing iOS app. This question may be very lame, but I could not find any solution or I could not understand the solution.…

santobedi
- 866
- 3
- 17
- 39
-1
votes
2 answers
Is it possible in Ruby to add singleton methods to an existing object, using variables in the local scope?
I want to add a singleton method code to the String object b = 'text'. It should be able to refer to the hash a defined in the local scope. But my attempt results in an error:
a = {'code'=>200, 'body'=>'text'}
b = a['body']
def b.code
return…

bioffe
- 6,283
- 3
- 50
- 65