added strategy example

This commit is contained in:
2024-11-11 10:28:35 +01:00
parent 7c614b0c5c
commit 51f5d352c6
5 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
package learn.simple_strategy;
public class Context {
private Strategy currentStrategy;
public Context(Strategy currentStrategy) {
this.currentStrategy = currentStrategy;
}
public void setCurrentStrategy(Strategy currentStrategy) {
this.currentStrategy = currentStrategy;
}
public void doSomeJob() {
currentStrategy.algorithm();
}
}