From 25b5a74454afcb21c0ba10ae920ca7f275083cce Mon Sep 17 00:00:00 2001 From: Susanne Date: Sun, 16 Feb 2025 16:43:09 +0100 Subject: [PATCH] =?UTF-8?q?Refactoring:=20vermeide=20identische=20Codebl?= =?UTF-8?q?=C3=B6cke=20+=20entferne=20redundanten=20Code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GameOfLifeAssignment/Life.class | Bin 2093 -> 2051 bytes out/test/GameOfLifeAssignment/LifeTest.class | Bin 1439 -> 1439 bytes src/Life.java | 9 +++++---- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/out/production/GameOfLifeAssignment/Life.class b/out/production/GameOfLifeAssignment/Life.class index d0084a203759dda198a7809d449dbdf04f8fddf6..dfb5eabfd118e8b00d8a5692c8ef73c912041550 100644 GIT binary patch delta 272 zcmXAj%}N4c7=@qDFP(8J5Ugl1N^O#6ilF}=RA?Og6KaAMU5!CrfG~@eMH^Rvi>N^G z7F=~Bt&2M5;yd4Y&(F*IQn)YlAF}OFEK@)-z}&u5ZrQ3Iys|iarfzGcG4(e!tOX_i zjWGAf?1W{Xm&Y{f;^r;V|rLsii7hAurs*WrrfWEV0Kn`|=LCiX@!L zxTH=^u|U_%%We>>?g^WE8950N$NF96&&3Rb%ri%?mg$c&w1~?Nj@f9w|1?AMGsJY#~i;hRv-4Ds=xq2cy=ak#8d(xDvpCF= zVxDmp@K{u`Bw(3Ma-6WjnPwMau2`j@hNo{2v(E-at%`FlvPeXeD(kH2cEoQ>8A@^^ zIN!u$81qHkxPvLXjol6|qt}yRZHqo(LzJ0NDZ>s^>}t`T)|RMfe!yWc5PLI6!DlS@ E17D3g8vp;GoY+FP}Tw{ zYssL%V9lV)U;|WRJ9!IBpQ0;Jg&RpF delta 109 zcmbQwJ)e8SH)csa1`Y;&20jJ@1`!5B1}O$(26+Y(1}z5D$^0xGvQ|J@YoM$RP}UYG zYsa9#;J~2D;0RRjGDLnwn8L)heGRvQ3* CF%Q)M diff --git a/src/Life.java b/src/Life.java index 53b91c7..8553f16 100644 --- a/src/Life.java +++ b/src/Life.java @@ -52,11 +52,12 @@ public class Life implements ILife { for (int y = 0; y < grid.length; y++) { 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); - } else if (countAliveNeighbours(x, y) == 2) { - next.setAlive(x, y); - } else if (countAliveNeighbours(x, y) < 2 || countAliveNeighbours(x, y) > 3) { + } + // Refactoring: zuvor gesetzte Bedingungen machen weitere Überprüfungen redundant + else { next.setDead(x, y); } }