mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-07 00:15:39 +00:00
docs: update double dispatch
This commit is contained in:
1 parent
4e0382ca9f
commit
30cb525c04
2 files changed
+52
-12
No files matched your search
@@ -56,6 +56,7 @@ public class App {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// initialize game objects and print their status
|
||||
LOGGER.info("Init objects and print their status");
|
||||
var objects = List.of(
|
||||
new FlamingAsteroid(0, 0, 5, 5),
|
||||
new SpaceStationMir(1, 1, 2, 2),
|
||||
@@ -63,18 +64,17 @@ public class App {
|
||||
new SpaceStationIss(12, 12, 14, 14)
|
||||
);
|
||||
objects.forEach(o -> LOGGER.info(o.toString()));
|
||||
LOGGER.info("");
|
||||
|
||||
// collision check
|
||||
LOGGER.info("Collision check");
|
||||
objects.forEach(o1 -> objects.forEach(o2 -> {
|
||||
if (o1 != o2 && o1.intersectsWith(o2)) {
|
||||
o1.collision(o2);
|
||||
}
|
||||
}));
|
||||
LOGGER.info("");
|
||||
|
||||
// output eventual object statuses
|
||||
LOGGER.info("Print object status after collision checks");
|
||||
objects.forEach(o -> LOGGER.info(o.toString()));
|
||||
LOGGER.info("");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user