On 7/15/06, transfire / gmail.com <transfire / gmail.com> wrote:
> Jan Molic recently contacted me about a slighlty modified version of
> his OrderedHash class that I distribute in Facets, the Dictionary
> class. There are a few variations of this class initself and Jan
> originally provided these via a subclass. I, on the other, thought
> alternate initializers would be better.
>
> Which is the best approach?
>
> Ex.
>
>   class AutoOrderHash < OrderedHash
>
>      def new(*args)
>         super(*args){ |h,k| h[k] = self.class.new }
>      end
>
>   end
>
> vs.
>
>   class OrderHash
>
>      def self.auto(*args)
>         new(*args){ |h,k| h[k] = self.class.new }
>      end
>
>   end
>
> Thanks,
> T.
>
I generally find it easier to remember what general kind of thing I
want (i.e. class) than what specific subtype of thing I want
(alternative initializer). For example, the Date class has a whole
load of alternative initializers which I usually have to look up. I
find it easier to wrap those in specific classes.

Using different classes, you have two pieces of information to correlate:
a) class name
b) signature of initializer

Using alternative initializers, you have three:
a) class name
b) method name of alternative initializer
c) alternative initializer signature

Just my tuppence worth.

Regards,
Sean