LLD - Behavioral Design Patterns — Part 1
Given the following code snippet using the State pattern, what will be the output?
class Context {
State state;
Context(State s) { state = s; }
void request() { state.handle(this); }
}
class State {
void handle(Context c) { System.out.println("State base"); }
}
class ConcreteStateA extends State {
void handle(Context c) { System.out.println("State A"); }
}
Context ctx = new Context(new ConcreteStateA());
ctx.request();