forked from john-bai/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecorator.java
More file actions
62 lines (46 loc) · 1.06 KB
/
Copy pathDecorator.java
File metadata and controls
62 lines (46 loc) · 1.06 KB
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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package designpatterns;
/**
*
* @author jtherrell
*/
abstract class VisualComponent {
abstract public void draw(Log log);
}
class TextView extends VisualComponent {
public void draw(Log log){log.append("text");}
}
abstract class Decorator extends VisualComponent {
private VisualComponent component;
public Decorator(VisualComponent component) {
this.component = component;
}
public void draw(Log log) {
component.draw(log);
}
}
class ScrollDecorator extends Decorator {
public ScrollDecorator(VisualComponent component) {
super(component);
}
@Override
public void draw(Log log) {
super.draw(log);
drawScroller(log);
}
private void drawScroller(Log log) {log.append("scroller");}
}
class BorderDecorator extends Decorator {
public BorderDecorator(VisualComponent component) {
super(component);
}
@Override
public void draw(Log log) {
super.draw(log);
drawBorder(log);
}
private void drawBorder(Log log) {log.append("border");}
}