mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 06:21:29 +00:00
moved specific logic in objects
This commit is contained in:
parent
58220c2358
commit
c02dc07db1
@ -1,9 +1,6 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
import com.gildedrose.item.Backstage;
|
|
||||||
import com.gildedrose.item.Brie;
|
|
||||||
import com.gildedrose.item.Item;
|
import com.gildedrose.item.Item;
|
||||||
import com.gildedrose.item.Sulfuras;
|
|
||||||
|
|
||||||
class GildedRose {
|
class GildedRose {
|
||||||
Item[] items;
|
Item[] items;
|
||||||
@ -16,56 +13,7 @@ class GildedRose {
|
|||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
final Item item = items[i];
|
final Item item = items[i];
|
||||||
item.updateSellIn();
|
item.updateSellIn();
|
||||||
if(item.name.equals(Brie.BRIE)){
|
item.updateQuality();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,13 +11,21 @@ public class Backstage extends Item {
|
|||||||
@Override
|
@Override
|
||||||
public void increaseQuality() {
|
public void increaseQuality() {
|
||||||
super.increaseQuality();
|
super.increaseQuality();
|
||||||
|
|
||||||
if (this.sellIn < 11 && this.quality < 50) {
|
if (this.sellIn < 11 && this.quality < 50) {
|
||||||
super.increaseQuality();
|
super.increaseQuality();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.sellIn < 6 && this.quality < 50) {
|
if (this.sellIn < 6 && this.quality < 50) {
|
||||||
super.increaseQuality();
|
super.increaseQuality();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateQuality() {
|
||||||
|
if (this.quality < 50) {
|
||||||
|
this.increaseQuality();
|
||||||
|
}
|
||||||
|
if (this.sellIn < 0) {
|
||||||
|
this.quality = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,4 +14,16 @@ public class Brie extends Item {
|
|||||||
super.increaseQuality();
|
super.increaseQuality();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateQuality(){
|
||||||
|
if (this.quality < 50) {
|
||||||
|
this.increaseQuality();
|
||||||
|
}
|
||||||
|
if (this.sellIn < 0) {
|
||||||
|
if (this.quality < 50) {
|
||||||
|
this.increaseQuality();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,17 @@ public class Item {
|
|||||||
this.quality = this.quality + 1;
|
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() {
|
public void updateSellIn() {
|
||||||
this.sellIn = this.sellIn - 1;
|
this.sellIn = this.sellIn - 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,4 +12,9 @@ public class Sulfuras extends Item {
|
|||||||
public void updateSellIn() {
|
public void updateSellIn() {
|
||||||
//NO-OP
|
//NO-OP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateQuality() {
|
||||||
|
//NO-OP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user