added strategy pattern sample
This commit is contained in:
18
strategy/src/main/java/com/iluwatar/DragonSlayer.java
Normal file
18
strategy/src/main/java/com/iluwatar/DragonSlayer.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public class DragonSlayer {
|
||||
|
||||
private DragonSlayingStrategy strategy;
|
||||
|
||||
public DragonSlayer(DragonSlayingStrategy strategy) {
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
public void changeStrategy(DragonSlayingStrategy strategy) {
|
||||
this.strategy = strategy;
|
||||
}
|
||||
|
||||
public void goToBattle() {
|
||||
strategy.execute();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user