moved specific logic in objects

This commit is contained in:
Sallah Kokaina 2019-11-01 19:52:49 +01:00
parent 58220c2358
commit c02dc07db1
5 changed files with 39 additions and 55 deletions

View File

@ -1,9 +1,6 @@
package com.gildedrose;
import com.gildedrose.item.Backstage;
import com.gildedrose.item.Brie;
import com.gildedrose.item.Item;
import com.gildedrose.item.Sulfuras;
class GildedRose {
Item[] items;
@ -16,56 +13,7 @@ class GildedRose {
for (int i = 0; i < items.length; i++) {
final Item item = items[i];
item.updateSellIn();
if(item.name.equals(Brie.BRIE)){
updateBrieQuality(item);
}else if (item.name.equals(Backstage.BACKSTAGE)){
updateBackstageQuality(item);
}else if (!item.name.equals(Sulfuras.SULFURAS)){
updateItemQuality(item);
}
}
}
private void updateItemQuality(Item item) {
if (!item.name.equals(Backstage.BACKSTAGE)) {
if (item.quality > 0 ) {
item.decreaseQuality();
}
}
else {
if (item.quality < 50) {
item.increaseQuality();
}
}
if (item.sellIn < 0) {
if (!item.name.equals(Backstage.BACKSTAGE)) {
if ( item.quality > 0) {
item.decreaseQuality();
}
} else {
item.quality = 0;
}
}
}
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();
}
item.updateQuality();
}
}

View File

@ -11,13 +11,21 @@ public class Backstage extends Item {
@Override
public void increaseQuality() {
super.increaseQuality();
if (this.sellIn < 11 && this.quality < 50) {
super.increaseQuality();
}
if (this.sellIn < 6 && this.quality < 50) {
super.increaseQuality();
}
}
@Override
public void updateQuality() {
if (this.quality < 50) {
this.increaseQuality();
}
if (this.sellIn < 0) {
this.quality = 0;
}
}
}

View File

@ -14,4 +14,16 @@ public class Brie extends Item {
super.increaseQuality();
}
}
@Override
public void updateQuality(){
if (this.quality < 50) {
this.increaseQuality();
}
if (this.sellIn < 0) {
if (this.quality < 50) {
this.increaseQuality();
}
}
}
}

View File

@ -27,6 +27,17 @@ public class Item {
this.quality = this.quality + 1;
}
public void updateQuality(){
if (this.quality > 0) {
this.decreaseQuality();
}
if (this.sellIn < 0) {
if (this.quality > 0) {
this.decreaseQuality();
}
}
}
public void updateSellIn() {
this.sellIn = this.sellIn - 1;
}

View File

@ -12,4 +12,9 @@ public class Sulfuras extends Item {
public void updateSellIn() {
//NO-OP
}
@Override
public void updateQuality() {
//NO-OP
}
}