State pattern implementation