[fxruby-users] Inheritance

Joel VanderWerf vjoel at path.berkeley.edu
Thu Feb 9 15:54:55 EST 2006


(I don't think Uwe's message showed up here because he cc-ed the list.)

Uwe Hartl wrote:
> Hi Joel,
> Thank you very much. It works like a charm!
> I have chosen the "factory" approach, because there I can inherit my 
> DataFixNum from other classes:
> 
> class DataFixNum
> 	def print
> 		puts "I am a DataFixNum!   " + self.to_s
> 	end
> end
> class DataTime
> 	def print
> 		puts "I am a DataTime!   " + self.to_s
> 	end
> end
> class Data
> 	def self.new(value)
> 		case value
> 			when Fixnum; DataFixNum.new
> 			when Time; DataTime.new
> 		end
> 	end
> end
> Data.new(23).print
> Data.new(Time.now).print
> 
> 
> Is there a particular reason why I should not use "new" here instead of 
> "self.new_from_value(d)" as you suggested?

You could do that too. I guess it would prevent actually instantiating
the base class, Data, but that may be ok.

-- 
      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


More information about the fxruby-users mailing list