Skip to content

Commit 142274f

Browse files
committed
implements Twin design pattern iluwatar#63, add credit and rephrase the comments
1 parent fdbfa9e commit 142274f

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

twin/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ inheritance in java
1717
**Applicability:** Use the Twin idiom when
1818

1919
* to simulate multiple inheritance in a language that does not support this feature.
20-
* to avoid certain problems of multiple inheritance such as name clashes.
20+
* to avoid certain problems of multiple inheritance such as name clashes.
21+
22+
**Credits:**
23+
24+
* [Twin – A Design Pattern for Modeling Multiple Inheritance](http://www.ssw.uni-linz.ac.at/Research/Papers/Moe99/Paper.pdf)

twin/src/main/java/com/iluwatar/twin/App.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,12 @@
33
/**
44
* Twin pattern is a design pattern which provides a standard solution to simulate multiple
55
* inheritance in java.
6-
*
76
* <p>
8-
* In this example, there is a ball game, a ball needs to subclass {@link GameItem} which provide
9-
* some common method like draw and click. Moreover, it needs to subclass {@link Thread} as ball is
10-
* a moving item (we use {@link Thread} instead of implements {@link Runnable} for example only)
11-
* <p>
12-
* Threre is scenario, when user click the ball, the ball will stop, when user click it gain, it
13-
* will resume to move. We create two class, ons is {@link BallItem} which subclass {@link GameItem}
14-
* , another is {@link BallThread} which subclass {@link Thread}. These two object both hold a field
15-
* named "Twin" reference to another object. In {@link BallItem#click()}, it will invoke
16-
* {@link BallThread} to suspend or resume moving; in {@link BallThread#run()}, it will invoke
17-
* {@link BallItem} for drawing.
18-
*
7+
* In this example, the essence of the Twin pattern is the {@link BallItem} class and
8+
* {@link BallThread} class represent the twin objects to coordinate with each other(via the twin
9+
* reference) like a single class inheriting from {@link GameItem} and {@link Thread}.
1910
*/
11+
2012
public class App {
2113

2214
/**
@@ -44,6 +36,7 @@ public static void main(String[] args) throws Exception {
4436

4537
waiting();
4638

39+
// exit
4740
ballThread.stopMe();
4841
}
4942

0 commit comments

Comments
 (0)