mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 06:21:29 +00:00
method extractions
This commit is contained in:
parent
8b1df0a5e6
commit
c4e303ef70
@ -9,7 +9,15 @@ public class AgedBrie implements CustomisedItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateState() {
|
public void updateState() {
|
||||||
|
decreaseSellByDayValueByOne();
|
||||||
|
increaseQualityByOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void decreaseSellByDayValueByOne() {
|
||||||
item.sellIn -= 1;
|
item.sellIn -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void increaseQualityByOne() {
|
||||||
item.quality += 1;
|
item.quality += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,15 +9,31 @@ public class BackstagePassesItem implements CustomisedItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateState() {
|
public void updateState() {
|
||||||
item.sellIn -= 1;
|
decreaseSellByDayValueByOne();
|
||||||
if (item.sellIn >= 11) {
|
if (sellByDayValueIsOver(10)) {
|
||||||
item.quality += 1;
|
increaseQualityBy(1);
|
||||||
} else if (item.sellIn > 5) {
|
} else if (sellByDayValueIsOver(5)) {
|
||||||
item.quality += 2;
|
increaseQualityBy(2);
|
||||||
} else if (item.sellIn > 0) {
|
} else if (sellByDayValueIsOver(0)) {
|
||||||
item.quality += 3;
|
increaseQualityBy(3);
|
||||||
} else {
|
} else {
|
||||||
item.quality = 0;
|
dropQualityToZero();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void decreaseSellByDayValueByOne() {
|
||||||
|
item.sellIn -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean sellByDayValueIsOver(int dayNumber) {
|
||||||
|
return item.sellIn > dayNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void increaseQualityBy(int qualityValue) {
|
||||||
|
item.quality += qualityValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dropQualityToZero() {
|
||||||
|
item.quality = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,12 +9,23 @@ public class ConjuredItem implements CustomisedItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateState() {
|
public void updateState() {
|
||||||
item.sellIn -= 1;
|
decreaseSellByDayValueByOne();
|
||||||
if (item.sellIn > 0) {
|
if (sellByDayValueIsOverZero()) {
|
||||||
item.quality -= 2;
|
decreaseQualityBy(2);
|
||||||
} else {
|
} else {
|
||||||
item.quality -= 4;
|
decreaseQualityBy(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void decreaseSellByDayValueByOne() {
|
||||||
|
item.sellIn -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean sellByDayValueIsOverZero() {
|
||||||
|
return item.sellIn > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void decreaseQualityBy(int qualityValue) {
|
||||||
|
item.quality -= qualityValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,13 +9,23 @@ public class StandardItem implements CustomisedItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateState() {
|
public void updateState() {
|
||||||
item.sellIn -= 1;
|
decreaseSellByDayValueByOne();
|
||||||
if (item.sellIn > 0) {
|
if (sellByDayValueIsOverZero()) {
|
||||||
item.quality -= 1;
|
decreaseQualityBy(1);
|
||||||
} else {
|
} else {
|
||||||
item.quality -= 2;
|
decreaseQualityBy(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void decreaseSellByDayValueByOne() {
|
||||||
|
item.sellIn -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean sellByDayValueIsOverZero() {
|
||||||
|
return item.sellIn > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void decreaseQualityBy(int qualityValue) {
|
||||||
|
item.quality -= qualityValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user