mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
🔨 convert ConjuredItem from anemic to rich
This commit is contained in:
parent
44f4e88689
commit
9ec9e54cb1
@ -19,7 +19,7 @@ public class ItemHandler {
|
||||
public boolean beforeSellInDate() {
|
||||
return item.sellIn >= 0;
|
||||
}
|
||||
|
||||
|
||||
public void decrementQuality() {
|
||||
item.quality = max(item.quality - 1, 0);
|
||||
}
|
||||
|
||||
@ -1,29 +1,46 @@
|
||||
package com.gildedrose.items;
|
||||
|
||||
import com.gildedrose.item_helpers.ItemHandler;
|
||||
import com.gildedrose.item_helpers.ItemType;
|
||||
import com.gildedrose.main.Item;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
public class ConjuredItem implements ItemType {
|
||||
|
||||
public static final String CONJURED = "Conjured Mana Cake";
|
||||
|
||||
private final ItemHandler item;
|
||||
private final Item item;
|
||||
|
||||
public ConjuredItem(Item item) {
|
||||
this.item = new ItemHandler(item);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateQuality() {
|
||||
item.decrementSellInDate();
|
||||
if (item.beforeSellInDate()) {
|
||||
item.decrementQualityBy2();
|
||||
decrementSellInDate();
|
||||
if (beforeSellInDate()) {
|
||||
decrementQualityBy2();
|
||||
} else {
|
||||
item.decrementQualityBy4();
|
||||
decrementQualityBy4();
|
||||
}
|
||||
}
|
||||
|
||||
public void decrementSellInDate() {
|
||||
item.sellIn--;
|
||||
}
|
||||
|
||||
public boolean beforeSellInDate() {
|
||||
return item.sellIn >= 0;
|
||||
}
|
||||
|
||||
public void decrementQualityBy2() {
|
||||
item.quality = max(item.quality - 2, 0);
|
||||
}
|
||||
|
||||
public void decrementQualityBy4() {
|
||||
item.quality = max(item.quality - 4, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return CONJURED;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user