no, i think you missed the structure.

  Miter <- Table[] <- Section[] <- Cell[] <- Element[].

a couple of people have suggested bringing everything into Top, i
thought about it, but that defeats the whole purpose of OO design.

the class variable makes sense. it didn't have to go in a seperate
module. it could have just gone straight into the Element class. i only
used the module b/c i actually use the prefix in two or the lower lower
classes. (table and element). anyhow, it makes sense b/c the prefix is
constant for all Elements (and Tables).

~transami


On Sun, 2002-07-07 at 12:46, Alan Chen wrote:
> On Sun, Jul 07, 2002 at 04:33:27PM +0900, Tom Sawyer wrote:
> > hey i found the answer! i got a clue from david. thanks david.
> > 
> > the trick is to use a class variable in a module, along with a class
> > method for setting it, and then include it in the "bottom" class.
> > 
> > module Prefix
> >   @@prefix
> >   def set_prefix(x)
> >     @@prefix = x
> >   end
> > end
> > 
> > class Bottom
> >   include Prefix
> >   def initialize
> >     puts @@prefix
> >   end
> > end
> > 
> > class Top
> >   def initialize
> >     Prefix.set_prefix('whatever')
> >   end
> > end
> > 
> > and bingo!
> > 
> > ~transami
> 
> That design looks a little ugly to me. For one, if you can't have more than
> one tree with different prefixes with that design.  You're esentially using
> an obfuscated global variable.  How about just passing prefix to the bottom
> element at instantiation?
> 
> class Bottom
>   def initialize(name)
>   end
> end
> 
> class Top
>   def initialize
>     @prefix = 'pro'
> 
>     @bottom_array = []
>   end
> 
>   def add_bottom(name)
>     @bottom_array << Bottom.new( "#{@prefix}_name" )
>   end
> end	
> -- 
> Alan Chen
> Digikata LLC
> http://digikata.com
> 
-- 
~transami

"They that can give up essential liberty to obtain a little
 temporary safety deserve neither liberty nor safety."
	-- Benjamin Franklin