I have an Action class, where an Action can do a range of things, including:

  1. Performing a sequential list of other actions
  2. Performing an action if a condition is true
  3. Allowing the user to pick between several different actions.

The last case that I mentioned is the tricky one. The project I am working is GUI based, and the main loop is not in my control. Hence, I need some way to tell the UI "offer the user a choice". There are two ways I've considered doing this:

  1. Have the act() function set some variable in the UI, then return. This makes Action #1 listed above difficult to implement (as it shouldn't increment to the next action). I may also have act() return true/false to determine whether or not it is finished, or include a isFinished() function.

  2. Have the Action class have a getNextActions() function that returns a List<Action>. If the list only has one element, it'll perform that one, otherwise give the user a list of choices.

I think both of these feel feasible, but I'm unsure which would be the best in terms of maintainability and code flexibility. Which option would be the best, or is there a 3rd option I haven't thought of?

  • Is this MVC? The controller is the logical place to tell the view to collect input via an event. However, the "main loop" is out of your control. Are there any hooks or other framework-level mechanisms to do this? – user22815 Feb 7 '15 at 6:39
  • Collecting input isn't the hard part. I'm struggling figuring out how to properly inform the UI that a choice needs to be made in the first place (because not all actions require a choice). – Nathan Merrill Feb 7 '15 at 8:46
  • That is what I said: "tell the view to collect input via an event." – user22815 Feb 7 '15 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.