Abstract Control Objects and Program Flow
I have a program flow problem that I hope some more experienced OOP
programmers can help me with.
I'm writing a scientific algorithm in Delphi. The program collects various
sorts of information from the user, and then proceeds to run an iterative
algorithm, plotting intermediate results on the screen and allowing the
user to stop it at any time.
The program presents several forms to the user to collect input. The first
form is always the same, but depending on the selections made there, the
program can branch. The input must be collected in the order that the
forms appear.
Currently, the program logic (branching control etc) is embedded in the
OKButtonClick event handlers for each form. I find this particularly
inelegant, and I wanted to create some kind of abstract control object that
has an appropriate method like ControlObject.CollectInputs. This would
allow me to keep the program flow control logic all in one place where it's
easy to read and modify.
My problem is this: I can't figure out a way to instantiate the
ControlObject and run the CollectInputs method. I could put it into the
OnCreate method of the MainForm, but that also seems inelegant: then the
whole program runs "inside" the MainForm.OnCreate method. Likewise, after
the algorithm finishes, the user should be able to start it again for a
different set of inputs. Thus, the MainForm has a menu bar, one item of
which is something like "Run". But again, when I click this menu item, the
whole program then runs "inside" the MainMenu.ItemRunClick event handler.
Is there some standard way to control program flow like this? Or is there
really no problem (except my spiritual longing for elegance) in running
everything inside MainForm.OnCreate and MainMenu.ItemRunClick? Being a
scientist rather than a real programmer, I sure could use some advice from
you more experienced guys!
--
Ken DeLong
Check out the FROG Web page at http://www.ca.sandia.gov/ultrafrog
Personal Page http://ourworld.compuserve.com/homepages/ken_delong