EDIT: this post only applies to Ruby 1.9
Hi,
At the toplevel method definition should result in private methods on Object, and tests seem to bear this out:
def hello; "hello world"; end
Object.private_instance_methods.include?(:hello) #=> true
Object.new.send(:hello) #=> "hello world"
However, the following also works (at toplevel)...
I have a singleton that is the main engine container for my game.
I have several abstract classes that make the developer implement the different calls to what that specific object needs.
What I want to do is to make my singleton call those methods upon each given object, but avoiding unecessary calls.
Example so you can understand bet...
I have a class that implements IHttpModule in a separate assembly from a website. The module implementation intercepts requests and rewrites urls for the website.
The mappings are stored in a class with the requested url and the destination url.
Is the second example, MTSingleton, from http://devhood.com/Tutorials/tutorial_details...
If a class implements a singleton pattern, should all the variables be declared static?
Is there any reason they shouldn't be declared static? Does it make a difference?
...
I want to have singleton class that its object is not statically created. having the following code, when I call ChromosomePool::createPool() I get the following error message :
--> ChromosomePool.h:50: undefined reference to `myga::ChromosomePool::pool' <--
Can anyone please tell me how can I solve the problem ?
class ChromosomePool ...
To clarify:
no I can't make this pure PHP5
yes this code works in PHP 4.3.9.
I don't have any real world experience implementing or supporting PHP4 but I had to recently change my class so it supports both PHP4 and PHP5.
Can anyone foresee any possible issues in regards to my implementation of the singleton method used here? I onl...
I want to have compact class based python DSLs in the following form:
class MyClass(Static):
z = 3
def _init_(cls, x=0):
cls._x = x
def set_x(cls, x):
cls._x = x
def print_x_plus_z(cls):
print cls._x + cls.z
@property
def x(cls):
return cls._x
class MyOtherClass(MyClass):
z...
When developing an application (web, win, whatever) which does alot of data access, is it better to keep your data access object open for the length of the request (i.e. do many things in a row, then close it when you finish), or keep opening and closing new ones?
protected aDataContext dc = new aDataContext();
vs
private aObject Get...
What is the best method for using singleton design pattern in conjunction with the factory method pattern in PHP5? My simplest usage scenario for this is instantiation selective database connection only once for each database type.
...
If you had a factory class that creates new objects of some kind, and that factroy class is a singleton, like this:
class Database_Factory extends Base_Factory {
private static $factory;
private $objects = array();
public function __get($profile) {
// check for object and return it if it's created before
}
...
We have used the Factory/Singlton pattern for creating a workflow runtime.
When we run a workflow we use a AutoResetEvent waitHandle.WaitOne() to wait for the workflow to complete.
If two workflows run at the same time they react to the same AutoResetEvent and both calls get the return values that were meant for the first call.
Is the...
I want to use a DB Singleton i created, in several Methods of a Class. Is it more appropriate to Instantiate the Singleton individually in each Method, or to Instantiate it through the __constructor() and access it from a variable in each method?
Thanks.
...
Hi
I am programming a website backend in PHP and I need to encapsulate $_SESSION in a class.
I've made my Session class a singleton but I am having trouble using it.
class Session
{
private static $instance;
public static $sessionID;
private function __construct()
{
session_start();
self::$ses...
I have a console application that is server based. I only want 1 instance of it running at once for a particular server (this is regardless of the user who might be running it).
I need to add a check to make sure only 1 instance of it is running, I can already do this by checking the running processes on the server, but is this best pr...
Hi,
I want to ensure that my C++ class is never instantiated before main() is entered. Is there any way to achieve this?
--
Some clarification:
I am writing an embedded application. My class must be static (reside in the BSS), but at instantiation it requires some resources that aren't available before certain things has been initial...
I have a Rails app that repeatedly talks to another Web server through a wrapper, and I'd like to stick the wrapper in a Singleton class so it's not recreated for every request. Easy enough, I thought:
class AppWrapper < Wrapper
include Singleton
end
...
wrapper = AppWrapper.instance "url"
Only it doesn't work:
wrong number of arg...
I would like to do this using java.util.logging if possible, any ideas? thanks.
...
How can i have user A and user B has the same instance of an object? I guess this would be across two different sessions.
TIA.
...
i think it makes sense to use boost::singleton together with a boost::logger, so that all the objects in the executable can access the same logger and dump strings to it.
class logger_singleton
: public boost::mutexed_singleton<logger_singleton>
{
private
boost::logger blogger;
public:
logger_singleton(boost::restricted);...
Problem: Our web console shows a list of all computers on which our application is installed. Each machine has some identification information that can be associated with it. Simple strings like department name, team name etc. We need to make it such that the user can change the name of these identification fields and add/remove as many ...