-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDecorator.java
More file actions
49 lines (40 loc) · 882 Bytes
/
Decorator.java
File metadata and controls
49 lines (40 loc) · 882 Bytes
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
interface Shape {
void draw();
}
class Circle implements Shape {
void draw() {
System.out.println("Circle");
}
}
class Rectangle implements Shape {
void draw() {
System.out.println("Rectangle");
}
}
abstract class DecoratedShape implements Shape {
Shape decoratedShape;
public DecoratedShape(Shape decoratedShape) {
this.decoratedShape = decoratedShape;
}
public void draw() {
decoratedShape.draw();
}
}
class RedDecoratedShape extends DecoratedShape {
public RedDecoratedShape(Shape decoratedShape) {
super(decoratedShape);
}
public void draw() {
decoratedShape.draw();
setRedBorder(decoratedShape);
}
private void setRedBorder(Shape decoratedShape) {
System.out.println("Set Red Border");
}
}
class Test {
public static void main(String[] args) {
Shape decoratedShape = new RedDecoratedShape(new Circle());
decoratedShape.draw();
}
}