-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecoratorPatternExample
More file actions
54 lines (43 loc) · 1.12 KB
/
DecoratorPatternExample
File metadata and controls
54 lines (43 loc) · 1.12 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
package ru.ezhov.groovy.decorator;
public class App {
public static void main(String[] args) {
Decorator1 decorator = new DecoratorLog1(
new DecoratorHttp1(
new DecoratorSimple1()
)
);
decorator.print();
}
}
interface Decorator1 {
void print();
}
class DecoratorHttp1 implements Decorator1 {
private Decorator1 decorator;
public DecoratorHttp1(Decorator1 decorator) {
this.decorator = decorator;
}
@Override
public void print() {
System.out.println("Print to http");
decorator.print();
}
}
class DecoratorLog1 implements Decorator1 {
private Decorator1 decorator;
public DecoratorLog1(Decorator1 decorator) {
this.decorator = decorator;
}
@Override
public void print() {
System.out.println("Hello I'm start logging action");
decorator.print();
System.out.println("I'm stop logging action");
}
}
class DecoratorSimple1 implements Decorator1 {
@Override
public void print() {
System.out.println("From simple decorator");
}
}