Separate qyality behavior in separate class

Same reason as for the sellIn behavior. We want to be able to provide
separate implementations and test them separately
This commit is contained in:
Bjorn Misseghers 2021-04-13 08:50:16 +02:00
parent 5f51644a8c
commit 11c697d7c5
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package com.gildedrose.behavior.quality;
import com.gildedrose.Item;
public class DefaultQualityBehavior implements QualityBehavior {
public static final int MAX_QUALITY_LEVEL = 50;
public static final int MIN_QUALITY_LEVEL = 0;
@Override
public void processQualityUpdate(Item item) {
decreaseQuality(item);
}
private void decreaseQuality(Item item) {
item.quality = limitQuality(item.quality - 1);
}
private int limitQuality(int newQuality) {
return Math.max(MIN_QUALITY_LEVEL, Math.min(MAX_QUALITY_LEVEL, newQuality));
}
}

View File

@ -0,0 +1,8 @@
package com.gildedrose.behavior.quality;
import com.gildedrose.Item;
public interface QualityBehavior {
void processQualityUpdate(Item item);
}