transfire wrote:
> I think the static class idea has thrown you off a bit. Not that I'm an
> expert on C#, but from what I've read it looks like a static class is
> how one implements the singleton _pattern_ in C#.

Well, actually, I think you do it the same way you would in C++, i.e., 
you have a static data member that is the ptr to the one instance 
(starting out as NULL) and the first time the constructor is called, you 
init it, and everytime after that, return the instance ptr.  (There are 
other ways involving private constructors)).  Though, my discussion 
above points out how, in essence, a static class is a singleton class 
(barring syntax differences).

The only reason I had this static class == singleton equivalence in my 
head was due to the actual example we were dealing with which was a 
class with two singleton methods (and no other methods or instance data 
members).  So, a class which contains only singleton methods would not 
be considered a singleton class?

> While Ruby has
> singleton.rb with its Singleton mixin to do this kind of thing, it's
> not nearly as useful b/c one can also use a module and its "singleton
> class" (i.e. adhoc/eigenclass) to get much of the same effect. The
> irony here, is though they can overlap in usage the later is actually
> quite different and has more uses.
> 
> So forget about the C# stuff for a moment and have a read of this page,
> 
>   http://rubygarden.org/ruby?SingletonTutorial
> 

Thanks for the link.  Yea, that does look like some powerful stuff. 
Seems to me that this sort of singleton (using the >> syntax) could be 
known as a 'singleton subclass' or a 'singleton extension.'  Any given 
class can have infinitely many  singleton subclases, no?

--J

-- 
Posted via http://www.ruby-forum.com/.