-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathDecoratorLesson.java
More file actions
40 lines (33 loc) · 889 Bytes
/
Copy pathDecoratorLesson.java
File metadata and controls
40 lines (33 loc) · 889 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
package patterns.structural;
public class DecoratorLesson {
public static void main(String[] args) {
FileStream fileStream = new FileBufferedReader(new FileStreamReader());
fileStream.read();
}
}
interface FileStream {
void read();
}
class FileStreamReader implements FileStream {
@Override
public void read() {
System.out.println("read file");
}
}
abstract class FileDecorator implements FileStream {
FileStream fileDecorator;
public FileDecorator(FileStream fileDecorator) {
this.fileDecorator = fileDecorator;
}
public abstract void read();
}
class FileBufferedReader extends FileDecorator {
public FileBufferedReader(FileStream fileDecorator) {
super(fileDecorator);
}
@Override
public void read() {
fileDecorator.read();
System.out.println("buffered read");
}
}