-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStrategy.java
41 lines (34 loc) · 976 Bytes
/
Strategy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
interface Strategy {
public void analyseSuperVillain (String name);
}
class Billionaire implements Strategy {
@Override
public void analyseSuperVillain(String name){
System.out.println("Give money and Settle Down");
}
}
class Vigilante implements Strategy{
@Override
public void analyseSuperVillain(String name){
System.out.println("Fight with "+name+" and then Settle Down");
}
}
class Situation {
Strategy saviourStrategy;
Situation(Strategy saviour){
this.saviourStrategy = saviour;
}
void handleIt(String superVillain){
this.saviourStrategy.analyseSuperVillain(superVillain);
}
}
class Main {
public static void main(String[] args){
Billionaire bruceWayne = new Billionaire();
Vigilante batman = new Vigilante();
Situation gothamInDanger = new Situation(bruceWayne);
gothamInDanger.handleIt("Joker");
Situation gothamInFire = new Situation(batman);
gothamInFire.handleIt("Ra's al Ghul");
}
}