2

Could someone help me with object-oriented design please? If I have to simulate tokens going through in different stages (from start to end with 3 middle stages) in a process, where a token can be moved from a stage to another at any point (except from end stage backwards), what would be the better design?

  1. A process class that contains 5 lists: List<Token> start, List<Token> middle1, etc.
  2. A process class that contains only 1 list: List<Token> with the Token class having a String stage variable that determines in which state the token is currently.

A process can have unlimited tokens in it at any stages. A token can be moved between stages as mentioned before. And a process can be listed with all of it's tokens in it.

Putting the question in another way: should a token object be aware of its own stage/state/location, or not.

Any other recommendations? Thanks in advance

vpiet
  • 21
  • 1
  • Is it a *functional* requirement for a Token to be aware of it's stage? – vikingsteve Mar 03 '15 at 11:53
  • In addition to my suspected duplicate, take a look at http://en.wikipedia.org/wiki/State_pattern Might be overkill for your case but still give you some ideas – André Stannek Mar 03 '15 at 11:53
  • If you choose solution 2, do not choose a String for storing the state but an Enum, it will be cleaner, and we will have the opportunity to put method on your state (for example : next state). – Luc DUZAN Mar 03 '15 at 12:46
  • Thanks for all the answers guys. Enum it is :) – vpiet Mar 04 '15 at 06:37

0 Answers0