Merge pull request #281 from ankurkaushal/master
Reformat according to google style guide
This commit is contained in:
@ -2,23 +2,24 @@ package com.iluwatar.templatemethod;
|
||||
|
||||
/**
|
||||
*
|
||||
* Template Method defines a skeleton for an algorithm. The algorithm subclasses
|
||||
* provide implementation for the blank parts.
|
||||
* Template Method defines a skeleton for an algorithm. The algorithm subclasses provide
|
||||
* implementation for the blank parts.
|
||||
* <p>
|
||||
* In this example {@link HalflingThief} contains {@link StealingMethod} that can be changed.
|
||||
* First the thief hits with {@link HitAndRunMethod} and then with {@link SubtleMethod}.
|
||||
* 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();
|
||||
}
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
@ -7,17 +7,17 @@ package com.iluwatar.templatemethod;
|
||||
*/
|
||||
public class HalflingThief {
|
||||
|
||||
private StealingMethod method;
|
||||
private StealingMethod method;
|
||||
|
||||
public HalflingThief(StealingMethod method) {
|
||||
this.method = method;
|
||||
}
|
||||
public HalflingThief(StealingMethod method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public void steal() {
|
||||
method.steal();
|
||||
}
|
||||
public void steal() {
|
||||
method.steal();
|
||||
}
|
||||
|
||||
public void changeMethod(StealingMethod method) {
|
||||
this.method = method;
|
||||
}
|
||||
public void changeMethod(StealingMethod method) {
|
||||
this.method = method;
|
||||
}
|
||||
}
|
||||
|
@ -7,19 +7,18 @@ package com.iluwatar.templatemethod;
|
||||
*/
|
||||
public class HitAndRunMethod extends StealingMethod {
|
||||
|
||||
@Override
|
||||
protected String pickTarget() {
|
||||
return "old goblin woman";
|
||||
}
|
||||
@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!");
|
||||
}
|
||||
@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!");
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,16 @@ package com.iluwatar.templatemethod;
|
||||
*/
|
||||
public abstract class StealingMethod {
|
||||
|
||||
protected abstract String pickTarget();
|
||||
protected abstract String pickTarget();
|
||||
|
||||
protected abstract void confuseTarget(String target);
|
||||
protected abstract void confuseTarget(String target);
|
||||
|
||||
protected abstract void stealTheItem(String target);
|
||||
protected abstract void stealTheItem(String target);
|
||||
|
||||
public void steal() {
|
||||
String target = pickTarget();
|
||||
System.out.println("The target has been chosen as " + target + ".");
|
||||
confuseTarget(target);
|
||||
stealTheItem(target);
|
||||
}
|
||||
public void steal() {
|
||||
String target = pickTarget();
|
||||
System.out.println("The target has been chosen as " + target + ".");
|
||||
confuseTarget(target);
|
||||
stealTheItem(target);
|
||||
}
|
||||
}
|
||||
|
@ -7,21 +7,18 @@ package com.iluwatar.templatemethod;
|
||||
*/
|
||||
public class SubtleMethod extends StealingMethod {
|
||||
|
||||
@Override
|
||||
protected String pickTarget() {
|
||||
return "shop keeper";
|
||||
}
|
||||
@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.");
|
||||
}
|
||||
@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.");
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,9 @@ import com.iluwatar.templatemethod.App;
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
String[] args = {};
|
||||
App.main(args);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user