Why wouldn't you do this?
module TreeStuff
class Node
end
class Tree < Node
end
end
Only because it's an annoying namespace level that the user would need
to either repeatedly specify or include. If I wrap all my own classes in
a Phrogz namespace, then the user needs to type:
tree = Phrogz::TreeStuff::Tree.new
and that's a little ugly IMHO. If a class can serve as its own
namespace, I think that it makes sense, to let it do so.
I also prefer to place subordinate/helper classes inside the class that
they augment. To my way of thinking, it makes little sense to use a
TreeStuff::Node outside of the context of a TreeStuff::Tree. As such, I
would prefer to see that implicit dependency suggested by letting the
Tree wrap its big old arms around the Node and say "MINE!".
But you raise a good point; that's certainly a good, simple way to
achieve the goal without spewing classes about willy-nilly.
···
From: matt neuburg [mailto:matt@tidbits.com]