Refactoring: vermeide zwei fast identische Codeblöcke (if-Abfragen)

This commit is contained in:
Susanne 2025-02-16 16:18:26 +01:00
parent 89bf74f0c3
commit 2763a28619
2 changed files with 3 additions and 3 deletions

View File

@ -54,9 +54,9 @@ public class Life implements ILife {
for (int x = 0; x < grid[y].length; x++) { for (int x = 0; x < grid[y].length; x++) {
if (countAliveNeighbours(x, y) == 3) { if (countAliveNeighbours(x, y) == 3) {
next.setAlive(x, y); next.setAlive(x, y);
} else if (countAliveNeighbours(x, y) < 2) { }
next.setDead(x, y); // Refactoring: vermeide zwei fast identische Codeblöcke, also Dopplung, mittels zusammenziehen der if's
} else if (countAliveNeighbours(x, y) > 3) { else if (countAliveNeighbours(x, y) < 2 || countAliveNeighbours(x, y) > 3) {
next.setDead(x, y); next.setDead(x, y);
} }
} }