mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 06:21:29 +00:00
moved specific backstage logic
This commit is contained in:
parent
0cb4b53cb4
commit
077ceb820a
@ -40,4 +40,3 @@
|
||||
-[x] encapsulate methods
|
||||
-[ ] isolate specific logics
|
||||
-[x] move specific logic to backstage
|
||||
-[x] replace items by specific objects in tests
|
||||
|
||||
@ -8,7 +8,6 @@ import com.gildedrose.item.Sulfuras;
|
||||
class GildedRose {
|
||||
Item[] items;
|
||||
|
||||
|
||||
public GildedRose(Item[] items) {
|
||||
this.items = items;
|
||||
}
|
||||
@ -18,48 +17,59 @@ class GildedRose {
|
||||
|
||||
final Item item = items[i];
|
||||
|
||||
if (!item.name.equals(Brie.BRIE) && !item.name.equals(Backstage.BACKSTAGE)) {
|
||||
if (item.quality > 0 && !item.name.equals(Sulfuras.SULFURAS)) {
|
||||
decreaseQualityByOne(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (item.quality < 50) {
|
||||
increaseQuality(item);
|
||||
}
|
||||
}
|
||||
item.updateSellIn();
|
||||
|
||||
updateSellIn(item);
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
if (item.name.equals(Brie.BRIE)) {
|
||||
if(item.name.equals(Brie.BRIE)){
|
||||
updateBrieQuality(item);
|
||||
}else if (item.name.equals(Backstage.BACKSTAGE)){
|
||||
updateBackstageQuality(item);
|
||||
}
|
||||
else{
|
||||
if (!item.name.equals(Backstage.BACKSTAGE)) {
|
||||
if (item.quality > 0 && !item.name.equals(Sulfuras.SULFURAS)) {
|
||||
item.decreaseQuality();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (item.quality < 50) {
|
||||
item.increaseQuality();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
if (!item.name.equals(Backstage.BACKSTAGE)) {
|
||||
if (!item.name.equals(Sulfuras.SULFURAS) && item.quality > 0) {
|
||||
decreaseQualityByOne(item);
|
||||
item.decreaseQuality();
|
||||
}
|
||||
} else {
|
||||
item.quality = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void decreaseQualityByOne(Item item) {
|
||||
item.decreaseQuality();
|
||||
}
|
||||
|
||||
private void increaseQuality(Item item) {
|
||||
item.increaseQuality();
|
||||
}
|
||||
|
||||
private void updateSellIn(Item item) {
|
||||
if (!item.name.equals(Sulfuras.SULFURAS)) {
|
||||
item.sellIn = item.sellIn - 1;
|
||||
private void updateBackstageQuality(Item item) {
|
||||
if (item.quality < 50) {
|
||||
item.increaseQuality();
|
||||
}
|
||||
if (item.sellIn < 0) {
|
||||
item.quality = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBrieQuality(Item item) {
|
||||
if (item.quality < 50) {
|
||||
item.increaseQuality();
|
||||
}
|
||||
if (item.sellIn < 0) {
|
||||
if (item.quality < 50) {
|
||||
item.increaseQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -7,4 +7,11 @@ public class Brie extends Item {
|
||||
public Brie(int sellIn, int quality) {
|
||||
super(BRIE, sellIn, quality);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increaseQuality(){
|
||||
if (this.quality < 50) {
|
||||
super.increaseQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,4 +26,8 @@ public class Item {
|
||||
public void increaseQuality() {
|
||||
this.quality = this.quality + 1;
|
||||
}
|
||||
|
||||
public void updateSellIn() {
|
||||
this.sellIn = this.sellIn - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,4 +7,9 @@ public class Sulfuras extends Item {
|
||||
public Sulfuras(int sellIn, int quality) {
|
||||
super(SULFURAS, sellIn, quality);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSellIn() {
|
||||
//NO-OP
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user