From: Benny Date: 2004-05-22T03:48:45+09:00 Subject: begging for a hint in app design dear list, with ruby you can quickly progress and suddenly I'm despaired, because I know I have to make decisions, but I don't know which ones :( I tried to break down the problem to its core so the following is pseudo code. its roughly the way my application currently works: ########## #the content of the main file of the app ########## module MyComponents class Components # what is common to all subclasses def initialize(args, other) @args = args @other = other # do something end def concat() return @args.to_s + @other.to_s end end end class MainClass attr_reader :other def initialize(file, compname, args, other) @file = file @compname = compname @args = args @other = other # do something end def ini_component() require(@file) puts eval("#{@comp_name.capitalize}.new(@args, @other)") # do something end end # this is in a loop: many the instances of MainClass are build with different parameters test = MainClass.new('testcomp.rb', 'mycomp', 'hi ', 'peter') test.ini_component # end of loop ###### #here comes an example file (testcomp.rb) with a component class in it ###### module MyComponents # there are pleny others of them, each class has its own rules # but once the behaviour is defined it wont change # (only "args" and "other" will change) class Mycomp < Components def initialize(args, other, specials = nil) @specials = specials if specials super(args, other) # do something depending on "args" and "other" return self.concat end end end so far from being elegant, this code kind of works. - I have plenty of MainClass instances and plenty of instances of subclasses of Components (though Im not sure, maybe a singleton is sufficient, since it does always the same (args and others are changing)) and the number of subclasses of Components will be growing as I intend to add the subclasses every now and then in new files, thats why I choose a module (don't want them to conflict with other classes flying around) - all components are only invoked by MainClass. my problem is: I dont want to pass "args" and "other" everytime a Components subclass is initialized (since its already in the MainClass) and I guess it is expensive. the components subclasses are only used within the context of MainClass. I want the app to be as fast as possible: what is the best design therefor (thinking of mixture, modules, inheritence etc)? thank you, benny