interface Strategy { void exec(); } class Context { private Strategy s; public Context(Strategy s) { this.s = s; } public void exec() { s.exec(); } } class StrategyA implements Strategy { public void exec() { System.out.println("StrategyA"); } } class StrategyB implements Strategy { public void exec() { System.out.println("StrategyB"); } } class Main { public static void main(String[] args) { new Context(new StrategyA()).exec(); new Context(new StrategyB()).exec(); } }