mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-19 08:21:37 +00:00
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:
parent
5f51644a8c
commit
11c697d7c5
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package com.gildedrose.behavior.quality;
|
||||||
|
|
||||||
|
import com.gildedrose.Item;
|
||||||
|
|
||||||
|
public interface QualityBehavior {
|
||||||
|
|
||||||
|
void processQualityUpdate(Item item);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user