From 2763a2861930c3ce1bcf814807d7e7fadf8f0066 Mon Sep 17 00:00:00 2001 From: Susanne Date: Sun, 16 Feb 2025 16:18:26 +0100 Subject: [PATCH] =?UTF-8?q?Refactoring:=20vermeide=20zwei=20fast=20identis?= =?UTF-8?q?che=20Codebl=C3=B6cke=20(if-Abfragen)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameOfLifeAssignment/Life.class | Bin 2082 -> 2065 bytes src/Life.java | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/out/production/GameOfLifeAssignment/Life.class b/out/production/GameOfLifeAssignment/Life.class index c741d49dee33bbffc22dff3d6f53e2e90456501f..aeea557d58dad0679433c17af500b79c87581739 100644 GIT binary patch delta 211 zcmZ1^Fi~K`bk_RE49pBH3=9m>yBQcGw=>B3Fx$##ZDEkuw}`=$*-jS3lraKw%(P@> zwlQe4Enwi$2C>waGsr@OSQj$zLM4|laDpZETbLP_|3BKo1SGd;ZvYz4%wP*7wHUa7 zq%i{rgDHbBgBgPY!(@3j4r^-$cLo~*hALIg9`uStr;4 delta 268 zcmXYr&r1SP6otR%Yt#lINfZ||(aK5p!vK{@i*s6?=j2 zy%44+1ia;XN#P0L|?01u0{4qsWae^1KnBiXL5#9RV6atxEYN3 V!ZrTt$|sJFCN|j;^Ax2=<`+A#FYy2X diff --git a/src/Life.java b/src/Life.java index 0779687..8459c37 100644 --- a/src/Life.java +++ b/src/Life.java @@ -54,9 +54,9 @@ public class Life implements ILife { for (int x = 0; x < grid[y].length; x++) { if (countAliveNeighbours(x, y) == 3) { next.setAlive(x, y); - } else if (countAliveNeighbours(x, y) < 2) { - next.setDead(x, y); - } else if (countAliveNeighbours(x, y) > 3) { + } + // Refactoring: vermeide zwei fast identische Codeblöcke, also Dopplung, mittels zusammenziehen der if's + else if (countAliveNeighbours(x, y) < 2 || countAliveNeighbours(x, y) > 3) { next.setDead(x, y); } }