Re: reflection a singleton class?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Nick Malik [Microsoft] (nickmalik_at_hotmail.nospam.com)
Date: 12/30/04


Date: Thu, 30 Dec 2004 21:58:28 GMT

why do you need to call Init on a singleton? initialization should be done
inside the singleton in its constructor.

If you need to call a method on the singleton, you need to get its instance
method to return the object. There is no other way. It should be no
different than calling any other static method.

-- 
--- Nick Malik [Microsoft]
    MCSD, CFPS, Certified Scrummaster
    http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
   I do not answer questions on behalf of my employer.  I'm just a
programmer helping programmers.
--
"Xing Zhou" <XingZhou@discussions.microsoft.com> wrote in message
news:24205E57-7D3B-4EA3-85A7-7E5558F1E265@microsoft.com...
> How to use reflection on a singlton object (i.e. the default constructor
is
> private)?
>
> I have a configuration file which contains a list of class names.  All
these
> class are simplified singleton type with the similar defintion as  below:
>
> public class S
> {
>     private S() {....}
>
>     public static S Instance  // can be replaced with a method if that
makes
> things easier
>    {
>        get { return _me; }
>     }
>     private static S _me = new S();
>
>     public void Init() { .....}  // do something
> };
>
> what I want to do is to invoked the Init() method on all these classes
> (whose names are defined in the configuration file).
>
> How can I achieve this?  Many thanks in advance for any help and/or
thought.


Relevant Pages

  • Re: Singletons
    ... A singleton would usually have a private constructor to prevent ... but you're then breaking one of the rules of the singleton pattern. ... public function __construct ...
    (php.general)
  • Re: Singletons
    ... A singleton would usually have a private constructor to prevent ... but you're then breaking one of the rules of the singleton pattern. ... public function __construct ...
    (php.general)
  • Re: Observer Design Pattern
    ... require 'singleton' ... singletons would have a static factory method ") to make themselves useful. ... how does the factory method decide which constructor to invoke? ... Will the include statement make the constructors become private if they were declared public? ...
    (comp.object)
  • Re: Singleton Pattern in VB 6
    ... objects/interfaces (one to manage creating the singleton and the singleton ... Firstly a constructor object/interface (consisting of a ... > Form wot I understand the constructor would create the singleton within ... and pass a copy back to the caller, while holdoing onto the original private ...
    (microsoft.public.vb.com)
  • Re: Can __new__ prevent __init__ from being called?
    ... so that the instance is initialized a second time. ... please consider the following class (a singleton in this case): ... def __init__: ... print 'in init' ...
    (comp.lang.python)