Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
61 lines (49 loc) · 1.08 KB

File metadata and controls

61 lines (49 loc) · 1.08 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
abstract class Girl {
String description = "plain";
public String getDescription() {
return description;
}
}
class AmericanGirl extends Girl {
public AmericanGirl() {
description = " + AmericanGirl";
}
}
class ChineseGirl extends Girl {
public ChineseGirl() {
description = " + ChineseGirl";
}
}
abstract class GirlDecorator extends Girl {
public abstract String getDescription();
}
class GoldenHair extends GirlDecorator {
private Girl girl;
public GoldenHair(Girl g) {
girl = g;
}
@Override
public String getDescription() {
return girl.getDescription() + " + with golden hair";
}
}
class Tall extends GirlDecorator {
private Girl girl;
public Tall(Girl g) {
this.girl = g;
}
@Override
public String getDescription() {
return girl.getDescription() + " + is very tall";
}
}
public class Decorator {
public static void main(String[] args) {
Girl g1 = new AmericanGirl();
System.out.println(g1.getDescription());
Girl g2 = new GoldenHair(g1);
System.out.println(g2.getDescription());
Girl g3 = new Tall(g2);
System.out.println(g3.getDescription());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.