class Context {
    State state
        
    Context(){
        this.state = new ConcreteStateA()
    }
    
    void setState(State state){
        this.state = state
    }
    
    void request(){
        state.handle(this)
    }

}

interface State {
    def handle(Context context)
}

class ConcreteStateA implements State {
    def handle(Context context){
        println "Handled with ConcreteStateA"
        // State change handled here
        context.setState(new ConcreteStateB())
    }
}

class ConcreteStateB implements State {
    def handle(Context context){
        println "Handled with ConcreteStateB"
        // State change handled here
        context.setState(new ConcreteStateA())
    }
}


// Simple Example

Context context = new Context()
5.times {
    context.request()
}
