Skip to content

Commit 1e989e7

Browse files
committed
wip
1 parent 4ef2bf8 commit 1e989e7

File tree

8 files changed

+112
-3
lines changed

8 files changed

+112
-3
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package j.bridge.delegate;
2+
3+
public class CountDisplay implements Displaible {
4+
private final Display display;
5+
6+
public CountDisplay(DisplayImpl impl) {
7+
this.display = new Display(impl);
8+
}
9+
10+
public void display() {
11+
display.display();
12+
}
13+
14+
public void multiDisplay(int times) {
15+
display.open();
16+
for (int i = 0; i < times; i++) {
17+
display.print();
18+
}
19+
display.close();
20+
}
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package j.bridge.delegate;
2+
3+
public interface Displaible {
4+
void display();
5+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package j.bridge.delegate;
2+
3+
public class Display implements Displaible {
4+
private final DisplayImpl impl;
5+
6+
public Display(DisplayImpl impl) {
7+
this.impl = impl;
8+
}
9+
10+
public void open() {
11+
impl.rawOpen();
12+
}
13+
14+
public void print() {
15+
impl.rawPrint();
16+
}
17+
18+
public void close() {
19+
impl.rawClose();
20+
}
21+
22+
public final void display() {
23+
open();
24+
print();
25+
close();
26+
}
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package j.bridge.delegate;
2+
3+
public interface DisplayImpl {
4+
void rawOpen();
5+
6+
void rawPrint();
7+
8+
void rawClose();
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package j.bridge.delegate;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
Displaible d1 = new Display(new StringDisplayImpl("Hello, Japan."));
6+
Displaible d2 = new CountDisplay(new StringDisplayImpl("Hello, World."));
7+
CountDisplay d3 = new CountDisplay(new StringDisplayImpl("Hello, Universe."));
8+
d1.display();
9+
d2.display();
10+
d3.display();
11+
d3.multiDisplay(5);
12+
}
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package j.bridge.delegate;
2+
3+
public class StringDisplayImpl implements DisplayImpl {
4+
private final String string;
5+
private final int width;
6+
7+
public StringDisplayImpl(String string) {
8+
this.string = string;
9+
this.width = string.length();
10+
}
11+
12+
@Override
13+
public void rawOpen() {
14+
printLine();
15+
}
16+
17+
@Override
18+
public void rawPrint() {
19+
System.out.println("|" + string + "|");
20+
}
21+
22+
@Override
23+
public void rawClose() {
24+
printLine();
25+
}
26+
27+
private void printLine() {
28+
System.out.print("+");
29+
for (int i = 0; i < width; i++) {
30+
System.out.print("-");
31+
}
32+
System.out.println("+");
33+
}
34+
}

src/main/java/j/bridge/inheritance/Display.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package j.bridge.inheritance;
22

33
public class Display {
4-
private DisplayImpl impl;
4+
private final DisplayImpl impl;
55

66
public Display(DisplayImpl impl) {
77
this.impl = impl;

src/main/java/j/bridge/inheritance/StringDisplayImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package j.bridge.inheritance;
22

33
public class StringDisplayImpl extends DisplayImpl {
4-
private String string;
5-
private int width;
4+
private final String string;
5+
private final int width;
66

77
public StringDisplayImpl(String string) {
88
this.string = string;

0 commit comments

Comments
 (0)