vendredi 6 février 2015

Designing an Action abstract class with GUI


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?





Aucun commentaire:

Enregistrer un commentaire