File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed
main/java/com/iluwatar/doubledispatch
test/java/com/iluwatar/doubledispatch Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 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 */
2626public 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 <>();
Original file line number Diff line number Diff line change 44
55import com .iluwatar .doubledispatch .App ;
66
7+ /**
8+ *
9+ * Application test
10+ *
11+ */
712public class AppTest {
813
914 @ Test
You can’t perform that action at this time.
0 commit comments