LLD - Behavioral Design Patterns — Part 1
Identify the error in this Java Strategy pattern code snippet:
interface Strategy { void execute(); }
class ConcreteStrategy implements Strategy {
public void execute() { System.out.println("Running"); }
}
class Context {
private Strategy strategy;
public Context() { }
public void setStrategy(Strategy s) { strategy = s; }
public void doWork() { strategy.execute(); }
}
Context c = new Context();
c.doWork();