State pattern implementation code