(Originally posted on 2016-06-04)
If your business logic starts getting complicated, it might mean that you should use finite state analysis and design. This technique is very popular for the artificial intelligence systems used in video games, and there are a number of finite state machine frameworks out there for Java, but they are all pretty heavyweight.
How does one create a lightweight state machine, and what is finite state analysis anyway? The ACM published a paper called "The Art of the State" by John F. Cigas in 1992.
In the paper, Professor Cigas describes how to do finite state analysis, and how to implement your state machines via a loop surrounding a switch statement... that's it... it's that simple.
Please read the paper. If it doesn't make any sense, then ask me how this is used, and I will show you. Please go to this page to get the PDF: http://portal.acm.org/citation.cfm?id=134541 The technique basically orders complex if-this-or-that-or-this-or-that type logic into the simplest form possible, and its really easy to do.