Refactoring: vermeide identische Codeblöcke + entferne redundanten Code

This commit is contained in:
Susanne 2025-02-16 16:43:09 +01:00
parent bcd68cee42
commit 25b5a74454
3 changed files with 5 additions and 4 deletions

View File

@ -52,11 +52,12 @@ public class Life implements ILife {
for (int y = 0; y < grid.length; y++) { for (int y = 0; y < grid.length; y++) {
for (int x = 0; x < grid[y].length; x++) { for (int x = 0; x < grid[y].length; x++) {
if (countAliveNeighbours(x, y) == 3) { // Refactoring: vermeide zwei fast identische Codeblöcke (if-Abfragen)
if (countAliveNeighbours(x, y) == 3 || countAliveNeighbours(x, y) == 2) {
next.setAlive(x, y); next.setAlive(x, y);
} else if (countAliveNeighbours(x, y) == 2) { }
next.setAlive(x, y); // Refactoring: zuvor gesetzte Bedingungen machen weitere Überprüfungen redundant
} else if (countAliveNeighbours(x, y) < 2 || countAliveNeighbours(x, y) > 3) { else {
next.setDead(x, y); next.setDead(x, y);
} }
} }