mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-14 22:21:20 +00:00
Item is passed in CustomisedItem contructor
This commit is contained in:
parent
cda1b03183
commit
35a0abea18
@ -15,7 +15,7 @@ class GildedRose {
|
||||
|
||||
public void updateQuality() {
|
||||
for (Item item : items) {
|
||||
itemFactory.customiseItem(item).updateState(item);
|
||||
itemFactory.customiseItem(item).updateState();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@ class AgedBrie extends CustomisedItem {
|
||||
private final Item item;
|
||||
|
||||
AgedBrie(Item item) {
|
||||
super(item);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ class BackstagePassesItem extends CustomisedItem {
|
||||
private final Item item;
|
||||
|
||||
BackstagePassesItem(Item item) {
|
||||
super(item);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ class ConjuredItem extends CustomisedItem {
|
||||
private final Item item;
|
||||
|
||||
ConjuredItem(Item item) {
|
||||
super(item);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
@ -2,13 +2,19 @@ package com.gildedrose.item;
|
||||
|
||||
public abstract class CustomisedItem {
|
||||
|
||||
public final void updateState(Item item) {
|
||||
private final Item item;
|
||||
|
||||
CustomisedItem(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public final void updateState() {
|
||||
item.sellIn = updatedItemSellIn();
|
||||
item.quality = updatedItemQuality();
|
||||
|
||||
if (hasReachedLowestQualityValue(item)) {
|
||||
if (hasReachedLowestQualityValue()) {
|
||||
item.quality = QualityValues.lowestValuePossible();
|
||||
} else if (hasReachedHighestQualityValue(item)) {
|
||||
} else if (hasReachedHighestQualityValue()) {
|
||||
item.quality = QualityValues.highestValuePossible(item);
|
||||
}
|
||||
}
|
||||
@ -17,11 +23,11 @@ public abstract class CustomisedItem {
|
||||
|
||||
abstract int updatedItemQuality();
|
||||
|
||||
private boolean hasReachedHighestQualityValue(Item item) {
|
||||
private boolean hasReachedHighestQualityValue() {
|
||||
return item.quality > QualityValues.highestValuePossible(item);
|
||||
}
|
||||
|
||||
private boolean hasReachedLowestQualityValue(Item item) {
|
||||
private boolean hasReachedLowestQualityValue() {
|
||||
return item.quality < QualityValues.lowestValuePossible();
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ class StandardItem extends CustomisedItem {
|
||||
private final Item item;
|
||||
|
||||
StandardItem(Item item) {
|
||||
super(item);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ class Sulfuras extends CustomisedItem {
|
||||
private final Item item;
|
||||
|
||||
Sulfuras(Item item) {
|
||||
super(item);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user