From: Hugh Sasse Staff Elec Eng Date: 2001-11-10T02:49:24+09:00 Subject: [ruby-talk:24780] Factories in Ruby. I've returned for a while... :-) I'm wondering if anyone can point me at good resouces (more than the GOF book) that explain about factory methods, or if someone has some clear ruby exmples. My problem is this: I am trying to write an optimiser (the details aren't too important) and I want it to be as re-usable as possible. At the moment I want to create several potential solutions at once, in the solution space, and initialise them randomly to some extent. So to keep this general I need: Number of dimensions of solution space Limits of each dimension of solution space number of possible solutions to optimise at once Block to pass to random_initialiser Block to pass to determine how good easch solution is Block to pass to determine how each solution is changed And that is just the stuff I have thought of now. The phrase "dog's breakfast" comes to mind. So I looked around the refactoring sites, looked at the patterns sites, and it seems that I need to have a generalised optimiser that creates the more specific optimiser which would have fewer parameters, so some kind of factory class is needed. I'm not sure how much YAGNI I can apply to this, I know I will be doing a fair bit with optimisation over the next few months, and I don't want to keep re-writing.... Is there an elegant way to do this? Thank you, Hugh