forked from hazukac/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPrinter.java
More file actions
33 lines (32 loc) · 979 Bytes
/
Printer.java
File metadata and controls
33 lines (32 loc) · 979 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
public class Printer implements Printable {
private String name;
public Printer() {
this.someHeavyJob("It needs a lot of time to create Printer instance...");
}
public Printer(String name) {
this.name = name;
this.someHeavyJob("It needs a lot of time to create " + this.name + " instance...");
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void print(String string) {
System.out.println("==== " + this.name + " ====");
System.out.println(string);
}
private void someHeavyJob(String message) {
System.out.println(message);
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// do something
}
System.out.print(".");
}
System.out.println("\nFinished.");
}
}