-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDecorator.java
86 lines (71 loc) · 1.7 KB
/
Decorator.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.*;
abstract class Ironman {
String description = "Ironman";
String getDescription(){
return description;
}
}
class MarkIII extends Ironman {
MarkIII(){
description = description + " MarkIII";
}
}
class MarkXLII extends Ironman {
MarkXLII(){
description = description + " MarkXLII";
}
}
abstract class IronmanDecorator extends Ironman{
abstract String getDescription();
}
class Model11 extends IronmanDecorator {
private Ironman ironman;
Model11(Ironman ironman){
this.ironman = ironman;
}
@Override
String getDescription(){
return ironman.getDescription() + " War Machine Armor";
}
void machineGun(){
System.out.println("Bullets -> -> ->");
}
}
class Model13 extends IronmanDecorator {
private Ironman ironman;
Model13(Ironman ironman){
this.ironman = ironman;
}
@Override
String getDescription(){
return ironman.getDescription() + " HulkBuster";
}
void smash(){
System.out.println("Boom Boom");
}
}
class Model44 extends IronmanDecorator {
private Ironman ironman;
Model44(Ironman ironman){
this.ironman = ironman;
}
@Override
String getDescription(){
return ironman.getDescription() + " Heavy Duty Armor";
}
void attack(){
System.out.println("Missile");
}
}
class Main{
public static void main(String[] args) {
Ironman tony = new MarkIII();
System.out.println(tony.getDescription());
Model11 tonyModel11 = new Model11(tony);
System.out.println(tonyModel11.getDescription());
tonyModel11.machineGun();
Model13 tonyModel13 = new Model13(tonyModel11);
System.out.println(tonyModel13.getDescription());
tonyModel13.smash();
}
}