When should you use State Pattern vs the Factory Pattern? Let's say I have an object that has different rules/policies based on the current state of it... and let's say I have 5 use cases (one for each state). Each state should flow to the next in a particular order. I see the factory pattern makes the code much cleaner, easier to debug and maintain since you have a different object for each state. The major problem, however, is that it's somewhat difficult to change state. For the State Pattern, you also have 5 different objects for each state, but only one core object. It's easy to incorporate different states into the object; however, it's not as easy to debug and maintain since now there are two objects to maintain instead of one (the state object and the object itself). What do others think? Thanks.
...
Go to the complete details ...