design patterns : strategy
This commit is contained in:
12
design-pattern/gof/src/strategy/after/BlueLightRedLight.java
Normal file
12
design-pattern/gof/src/strategy/after/BlueLightRedLight.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package strategy.after;
|
||||
|
||||
public class BlueLightRedLight {
|
||||
|
||||
public void blueLight(Speed speed) {
|
||||
speed.blueLight();
|
||||
}
|
||||
|
||||
public void redLight(Speed speed) {
|
||||
speed.redLight();
|
||||
}
|
||||
}
|
||||
10
design-pattern/gof/src/strategy/after/Client.java
Normal file
10
design-pattern/gof/src/strategy/after/Client.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package strategy.after;
|
||||
|
||||
public class Client {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BlueLightRedLight game = new BlueLightRedLight();
|
||||
game.blueLight(new Normal());
|
||||
game.redLight(new Faster());
|
||||
}
|
||||
}
|
||||
13
design-pattern/gof/src/strategy/after/Faster.java
Normal file
13
design-pattern/gof/src/strategy/after/Faster.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package strategy.after;
|
||||
|
||||
public class Faster implements Speed {
|
||||
@Override
|
||||
public void blueLight() {
|
||||
System.out.println("무궁화꽃이");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redLight() {
|
||||
System.out.println("피었습니다.");
|
||||
}
|
||||
}
|
||||
13
design-pattern/gof/src/strategy/after/Fastest.java
Normal file
13
design-pattern/gof/src/strategy/after/Fastest.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package strategy.after;
|
||||
|
||||
public class Fastest implements Speed {
|
||||
@Override
|
||||
public void blueLight() {
|
||||
System.out.println("무광꼬치");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redLight() {
|
||||
System.out.println("피어씀다");
|
||||
}
|
||||
}
|
||||
13
design-pattern/gof/src/strategy/after/Normal.java
Normal file
13
design-pattern/gof/src/strategy/after/Normal.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package strategy.after;
|
||||
|
||||
public class Normal implements Speed {
|
||||
@Override
|
||||
public void blueLight() {
|
||||
System.out.println("무 궁 화 꽃 이");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void redLight() {
|
||||
System.out.println("피 었 습 니 다.");
|
||||
}
|
||||
}
|
||||
7
design-pattern/gof/src/strategy/after/Speed.java
Normal file
7
design-pattern/gof/src/strategy/after/Speed.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package strategy.after;
|
||||
|
||||
public interface Speed {
|
||||
|
||||
void blueLight();
|
||||
void redLight();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package strategy.before;
|
||||
|
||||
public class BlueLightRedLight {
|
||||
|
||||
private int speed;
|
||||
|
||||
public BlueLightRedLight(int speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public void blueLight() {
|
||||
if (speed == 1) {
|
||||
System.out.println("무 궁 화 꽃 이");
|
||||
} else if (speed == 2) {
|
||||
System.out.println("무궁화꽃이");
|
||||
} else {
|
||||
System.out.println("무광꼬치");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void redLight() {
|
||||
if (speed == 1) {
|
||||
System.out.println("피 었 습 니 다.");
|
||||
} else if (speed == 2) {
|
||||
System.out.println("피었습니다.");
|
||||
} else {
|
||||
System.out.println("피어씀다");
|
||||
}
|
||||
}
|
||||
}
|
||||
10
design-pattern/gof/src/strategy/before/Client.java
Normal file
10
design-pattern/gof/src/strategy/before/Client.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package strategy.before;
|
||||
|
||||
public class Client {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BlueLightRedLight blueLightRedLight = new BlueLightRedLight(3);
|
||||
blueLightRedLight.blueLight();
|
||||
blueLightRedLight.redLight();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user