implements Twin design pattern #63, add credit and rephrase the comments
This commit is contained in:
parent
fdbfa9e8ee
commit
142274f3f7
@ -18,3 +18,7 @@ inheritance in java
|
||||
|
||||
* to simulate multiple inheritance in a language that does not support this feature.
|
||||
* to avoid certain problems of multiple inheritance such as name clashes.
|
||||
|
||||
**Credits:**
|
||||
|
||||
* [Twin – A Design Pattern for Modeling Multiple Inheritance](http://www.ssw.uni-linz.ac.at/Research/Papers/Moe99/Paper.pdf)
|
@ -3,20 +3,12 @@ package com.iluwatar.twin;
|
||||
/**
|
||||
* Twin pattern is a design pattern which provides a standard solution to simulate multiple
|
||||
* inheritance in java.
|
||||
*
|
||||
* <p>
|
||||
* In this example, there is a ball game, a ball needs to subclass {@link GameItem} which provide
|
||||
* some common method like draw and click. Moreover, it needs to subclass {@link Thread} as ball is
|
||||
* a moving item (we use {@link Thread} instead of implements {@link Runnable} for example only)
|
||||
* <p>
|
||||
* Threre is scenario, when user click the ball, the ball will stop, when user click it gain, it
|
||||
* will resume to move. We create two class, ons is {@link BallItem} which subclass {@link GameItem}
|
||||
* , another is {@link BallThread} which subclass {@link Thread}. These two object both hold a field
|
||||
* named "Twin" reference to another object. In {@link BallItem#click()}, it will invoke
|
||||
* {@link BallThread} to suspend or resume moving; in {@link BallThread#run()}, it will invoke
|
||||
* {@link BallItem} for drawing.
|
||||
*
|
||||
* In this example, the essence of the Twin pattern is the {@link BallItem} class and
|
||||
* {@link BallThread} class represent the twin objects to coordinate with each other(via the twin
|
||||
* reference) like a single class inheriting from {@link GameItem} and {@link Thread}.
|
||||
*/
|
||||
|
||||
public class App {
|
||||
|
||||
/**
|
||||
@ -44,6 +36,7 @@ public class App {
|
||||
|
||||
waiting();
|
||||
|
||||
// exit
|
||||
ballThread.stopMe();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user