On Thursday 18 November 2004 10:28 am, Florian Gross wrote:
| trans. (T. Onoma) wrote:
| > Sure. One could do that, but it lacks for straightforward instantiation
| > and can't be subclassed. Since it amount to the about same thing, it just
| > seems easier to create a Singleton.
|
| Subclassing is done by .dup()ing the Object and then adding new methods.
| I still don't know why you need "instantiation" (don't we usually
| instantiate with .new? -- Yet singleton.rb forces you to use .instance).

Give me a prototype-based OOPL, baby! Yes, I dislike using #instance usually, 
and have changed it to #new before. If you do that an interesting consequence 
arises --you can force all one's code to use the same instance irregardless. 
(Although I don't know how useful that is in practice, but it's interesting 
nonetheless.)

| I don't get why one needs "include Singleton" there -- it looks like it
| would make perfect sense to be able to have multiple pools. Are you sure
| you are not using a Singleton for making one single pool easily
| reachable from anywhere in your application? There's better alternatives
| for that.

| Well, I'd rather use a Class in this context. Limiting the amount of
| Pools to 1 seems a bit arbitrary.

Yes. You could Of course. The idea is that there should be one and one of 
these pools. But perhaps that is unnecessarily enforced, and docs can specify 
"USE THIS CONSTANT".

| > | Still, I feel like "singleton class" is used more than the others.
| > | Maybe you could grep #ruby-talk logs and compare the usage of the
| > | terms? (But be sure to filter out the few occurrences of
| > | SingleInstanceClasses that currently share the same name or the
| > | statistic will be slightly biased.)
| >
| > How to access those logs?
|
| Hm, sorry, I can not find an official site that has them. But I could
| package up my own local ones and mail them to you, if that is of help.

Getting back to the earlier notion. This is basically what I decided. In my 
lib I created Object#special_class and aliased #singleton_class to it. In the 
future I will refer to it as the "special singleton" or "singleton 
special-class".

| > | > The monotheistic doctrine of an OOP developer: God is Singleton.
| > |
| > | Most gods want you to believe that so that they can get power
| > | exclusively. Having just one god will make it difficult to replace it
| > | by a mock god when testing your believes.
| >
| > LOL :) Test God? That'll be some interesting code.
| >
| >   assert_divine(GodClass)
| >
| > What kind of error message would you expect? A bolt of lightening? :)
|
| Maybe a wide angle disintegration ray.

Oo.. that'll hurt! :-)

Laters,
T.