From fde7f71704a82f9a54463a044128e77bc8381305 Mon Sep 17 00:00:00 2001 From: Ilkka Seppala Date: Fri, 21 Aug 2015 23:19:55 +0300 Subject: [PATCH] #107 Template Method JavaDoc --- .../java/com/iluwatar/templatemethod/App.java | 44 ++++++++------- .../templatemethod/HalflingThief.java | 46 ++++++++-------- .../templatemethod/HitAndRunMethod.java | 50 ++++++++--------- .../iluwatar/templatemethod/SubtleMethod.java | 54 +++++++++---------- .../com/iluwatar/templatemethod/AppTest.java | 33 +++++++----- 5 files changed, 118 insertions(+), 109 deletions(-) diff --git a/template-method/src/main/java/com/iluwatar/templatemethod/App.java b/template-method/src/main/java/com/iluwatar/templatemethod/App.java index 9797474cf..c9927e91b 100644 --- a/template-method/src/main/java/com/iluwatar/templatemethod/App.java +++ b/template-method/src/main/java/com/iluwatar/templatemethod/App.java @@ -1,20 +1,24 @@ -package com.iluwatar.templatemethod; - -/** - * - * Template Method defines a skeleton for an algorithm. The algorithm subclasses - * provide implementation for the blank parts. - * - * In this example HalflingThief contains StealingMethod that can be changed. - * First the thief hits with HitAndRunMethod and then with SubtleMethod. - * - */ -public class App { - - public static void main(String[] args) { - HalflingThief thief = new HalflingThief(new HitAndRunMethod()); - thief.steal(); - thief.changeMethod(new SubtleMethod()); - thief.steal(); - } -} +package com.iluwatar.templatemethod; + +/** + * + * Template Method defines a skeleton for an algorithm. The algorithm subclasses + * provide implementation for the blank parts. + *

+ * In this example {@link HalflingThief} contains {@link StealingMethod} that can be changed. + * First the thief hits with {@link HitAndRunMethod} and then with {@link SubtleMethod}. + * + */ +public class App { + + /** + * Program entry point + * @param args command line args + */ + public static void main(String[] args) { + HalflingThief thief = new HalflingThief(new HitAndRunMethod()); + thief.steal(); + thief.changeMethod(new SubtleMethod()); + thief.steal(); + } +} diff --git a/template-method/src/main/java/com/iluwatar/templatemethod/HalflingThief.java b/template-method/src/main/java/com/iluwatar/templatemethod/HalflingThief.java index 3cdb2f1b1..4d6cecb9f 100644 --- a/template-method/src/main/java/com/iluwatar/templatemethod/HalflingThief.java +++ b/template-method/src/main/java/com/iluwatar/templatemethod/HalflingThief.java @@ -1,23 +1,23 @@ -package com.iluwatar.templatemethod; - -/** - * - * Halfling thief uses StealingMethod to steal. - * - */ -public class HalflingThief { - - private StealingMethod method; - - public HalflingThief(StealingMethod method) { - this.method = method; - } - - public void steal() { - method.steal(); - } - - public void changeMethod(StealingMethod method) { - this.method = method; - } -} +package com.iluwatar.templatemethod; + +/** + * + * Halfling thief uses {@link StealingMethod} to steal. + * + */ +public class HalflingThief { + + private StealingMethod method; + + public HalflingThief(StealingMethod method) { + this.method = method; + } + + public void steal() { + method.steal(); + } + + public void changeMethod(StealingMethod method) { + this.method = method; + } +} diff --git a/template-method/src/main/java/com/iluwatar/templatemethod/HitAndRunMethod.java b/template-method/src/main/java/com/iluwatar/templatemethod/HitAndRunMethod.java index 78ee2031b..633e52895 100644 --- a/template-method/src/main/java/com/iluwatar/templatemethod/HitAndRunMethod.java +++ b/template-method/src/main/java/com/iluwatar/templatemethod/HitAndRunMethod.java @@ -1,25 +1,25 @@ -package com.iluwatar.templatemethod; - -/** - * - * HitAndRunMethod implementation of StealingMethod. - * - */ -public class HitAndRunMethod extends StealingMethod { - - @Override - protected String pickTarget() { - return "old goblin woman"; - } - - @Override - protected void confuseTarget(String target) { - System.out.println("Approach the " + target + " from behind."); - } - - @Override - protected void stealTheItem(String target) { - System.out.println("Grab the handbag and run away fast!"); - } - -} +package com.iluwatar.templatemethod; + +/** + * + * HitAndRunMethod implementation of {@link StealingMethod}. + * + */ +public class HitAndRunMethod extends StealingMethod { + + @Override + protected String pickTarget() { + return "old goblin woman"; + } + + @Override + protected void confuseTarget(String target) { + System.out.println("Approach the " + target + " from behind."); + } + + @Override + protected void stealTheItem(String target) { + System.out.println("Grab the handbag and run away fast!"); + } + +} diff --git a/template-method/src/main/java/com/iluwatar/templatemethod/SubtleMethod.java b/template-method/src/main/java/com/iluwatar/templatemethod/SubtleMethod.java index c5bd1cfaf..f506d682b 100644 --- a/template-method/src/main/java/com/iluwatar/templatemethod/SubtleMethod.java +++ b/template-method/src/main/java/com/iluwatar/templatemethod/SubtleMethod.java @@ -1,27 +1,27 @@ -package com.iluwatar.templatemethod; - -/** - * - * SubtleMethod implementation of StealingMethod. - * - */ -public class SubtleMethod extends StealingMethod { - - @Override - protected String pickTarget() { - return "shop keeper"; - } - - @Override - protected void confuseTarget(String target) { - System.out.println("Approach the " + target - + " with tears running and hug him!"); - } - - @Override - protected void stealTheItem(String target) { - System.out.println("While in close contact grab the " + target - + "'s wallet."); - } - -} +package com.iluwatar.templatemethod; + +/** + * + * SubtleMethod implementation of {@link StealingMethod}. + * + */ +public class SubtleMethod extends StealingMethod { + + @Override + protected String pickTarget() { + return "shop keeper"; + } + + @Override + protected void confuseTarget(String target) { + System.out.println("Approach the " + target + + " with tears running and hug him!"); + } + + @Override + protected void stealTheItem(String target) { + System.out.println("While in close contact grab the " + target + + "'s wallet."); + } + +} diff --git a/template-method/src/test/java/com/iluwatar/templatemethod/AppTest.java b/template-method/src/test/java/com/iluwatar/templatemethod/AppTest.java index fce07bef1..bd4e2d332 100644 --- a/template-method/src/test/java/com/iluwatar/templatemethod/AppTest.java +++ b/template-method/src/test/java/com/iluwatar/templatemethod/AppTest.java @@ -1,14 +1,19 @@ -package com.iluwatar.templatemethod; - -import org.junit.Test; - -import com.iluwatar.templatemethod.App; - -public class AppTest { - - @Test - public void test() { - String[] args = {}; - App.main(args); - } -} +package com.iluwatar.templatemethod; + +import org.junit.Test; + +import com.iluwatar.templatemethod.App; + +/** + * + * Application test + * + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +}