X Tutup
Skip to content

Commit f2db01e

Browse files
committed
iluwatar#107 Double Dispatch example JavaDoc
1 parent 57e702d commit f2db01e

File tree

2 files changed

+13
-4
lines changed
  • double-dispatch/src

2 files changed

+13
-4
lines changed

double-dispatch/src/main/java/com/iluwatar/doubledispatch/App.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88
* When a message with a parameter is sent to an object, the resultant behaviour is defined by the
99
* implementation of that method in the receiver. Sometimes the behaviour must also be determined
1010
* by the type of the parameter.
11-
*
11+
* <p>
1212
* One way to implement this would be to create multiple instanceof-checks for the methods parameter.
1313
* However, this creates a maintenance issue. When new types are added we would also need to change
1414
* the method's implementation and add a new instanceof-check. This violates the single responsibility
1515
* principle - a class should have only one reason to change.
16-
*
16+
* <p>
1717
* Instead of the instanceof-checks a better way is to make another virtual call on the parameter
1818
* object. This way new functionality can be easily added without the need to modify existing
1919
* implementation (open-closed principle).
20-
*
21-
* In this example we have hierarchy of objects (GameObject) that can collide to each other. Each
20+
* <p>
21+
* In this example we have hierarchy of objects ({@link GameObject}) that can collide to each other. Each
2222
* object has its own coordinates which are checked against the other objects' coordinates. If
2323
* there is an overlap, then the objects collide utilizing the Double Dispatch pattern.
2424
*
2525
*/
2626
public class App {
2727

28+
/**
29+
* Program entry point
30+
* @param args command line args
31+
*/
2832
public static void main( String[] args ) {
2933
// initialize game objects and print their status
3034
List<GameObject> objects = new ArrayList<>();

double-dispatch/src/test/java/com/iluwatar/doubledispatch/AppTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
import com.iluwatar.doubledispatch.App;
66

7+
/**
8+
*
9+
* Application test
10+
*
11+
*/
712
public class AppTest {
813

914
@Test

0 commit comments

Comments
 (0)
X Tutup