State pattern is probably most used in review cycles. The definition says:

State pattern allows an object to appear as it can change its class by altering its behaviour and state.

What are you talking about?

Well, imagine you are in need to build a bug tracking database.  Bug reports in basics have four states. First they are unassigned until someone is solving them. When they are taken over, they become assigned, specifying that someone is already working on them. After bug fix has been produced, it is a good practice to send it to testing. Then it is up to QA to confirm that bug fix is complete or whether it is not.

Show me the code!

Example will be based on simple bug report specified above. However, I will skip actual action implementation as it varies based on application needs. Instead, I will use message box to print out the action report.

So, now, first what you need is a state abstract class that will implement all methods needed for transition between states (in our case: unassigned, assigned, send to testing and complete).

Then, what you need is a context class that will be used when changing state of a bug report.

And now, we need to implement all four states classes.

This is all there is to it. To test it, I wrote a simple agent that goes through states and in each new state also tests wrong transitions (e.g. from unassigned to complete etc.).