mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-03 13:12:17 +00:00
#107 JavaDoc for Strategy
This commit is contained in:
1 parent
ed416ac759
commit
934f99e2a9
2 files changed
+45
-36
No files matched your search
@@ -1,22 +1,26 @@
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
/**
|
||||
*
|
||||
* Strategy (DragonSlayingStrategy) encapsulates an algorithm. The containing
|
||||
* object (DragonSlayer) can alter its behavior by changing its strategy.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Green dragon spotted ahead!");
|
||||
DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
System.out.println("Red dragon emerges.");
|
||||
dragonSlayer.changeStrategy(new ProjectileStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
System.out.println("Black dragon lands before you.");
|
||||
dragonSlayer.changeStrategy(new SpellStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
}
|
||||
}
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
/**
|
||||
*
|
||||
* Strategy ({@link DragonSlayingStrategy}) encapsulates an algorithm. The containing
|
||||
* object ({@link DragonSlayer}) can alter its behavior by changing its strategy.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Green dragon spotted ahead!");
|
||||
DragonSlayer dragonSlayer = new DragonSlayer(new MeleeStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
System.out.println("Red dragon emerges.");
|
||||
dragonSlayer.changeStrategy(new ProjectileStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
System.out.println("Black dragon lands before you.");
|
||||
dragonSlayer.changeStrategy(new SpellStrategy());
|
||||
dragonSlayer.goToBattle();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,19 @@
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.iluwatar.strategy.App;
|
||||
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
||||
package com.iluwatar.strategy;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.iluwatar.strategy.App;
|
||||
|
||||
/**
|
||||
*
|
||||
* Application test
|
||||
*
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user