From: Robert Dober Date: 2008-04-12T02:13:55+09:00 Subject: Re: Designing Namespaces On Fri, Apr 11, 2008 at 6:29 PM, ara.t.howard wrote: > > On Apr 11, 2008, at 9:28 AM, Trans wrote: > > > > > What are other people experiences with all this? Do you find it better > > use highly categorized namespaces and to stick with namespace/filename > > mapping? Or have you too found alternates organizations you prefer? > > > > Thanks, > > > > child classes should be inner classes - saves a ton of typing > > > class WindInstrument > > class Trumpet < WindInstrument > end > > class Carinet < WindInstrument > end > > end > > > and then use shortcuts > > > def Music.trumpet *a, &b > > if a.empty? and b.nil? > > WindInstrument::Trumpet > > else > > WindInstrument::Trumpet.new *a, &b > > end > > > trumpet = Music.trumpet(arg, arg){ block } > > > so the two main concepts are: > > - nest classes under parent > - assign shortcuts > > i'm not strict with that - but both are useful for maintaining sanity. i > esp like > > children = Parent.constants.select{|c| Parent > Parent.const_get(c)} > > not that code - but you get the idea > > a @ http://codeforpeople.com/ > -- > we can deny everything, except that we have the possibility of being > better. simply reflect on that. > h.h. the 14th dalai lama > > > > > Very interesting approach Ara, allow me to express some skepticism about the shortcut delivering either the class or an instance of it. The idea is sure enough brilliant as a solution to name pollution, I wonder however if it is not a maintenance trap... Now if it became a well known pattern this danger would go away. In order to easier recognize the pattern I would suggest to use Capitalized names for your shortcut/factory methods. How does that feel? Cheers Robert -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein