mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 15:01:28 +00:00
create subclass for AgedBrie
creating AgedBrie class to implement the methhods for each type alone
This commit is contained in:
parent
4fa88bab43
commit
77fca57da8
17
Java/src/main/java/com/gildedrose/AgeddBrie.java
Normal file
17
Java/src/main/java/com/gildedrose/AgeddBrie.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class AgeddBrie extends StorageItem {
|
||||
public AgeddBrie(Item item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateQuality() {
|
||||
increaseQuality();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExpired() {
|
||||
increaseQuality();
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,7 @@ class GildedRose {
|
||||
|
||||
public void updateStorage() {
|
||||
for (Item item : items) {
|
||||
new StrorageItem(item).dailyUpdateItem();
|
||||
StorageItem.createItem(item).dailyUpdateItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,19 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class StrorageItem {
|
||||
public class StorageItem {
|
||||
public static final String AGED_BRIE = "Aged Brie";
|
||||
public static final String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert";
|
||||
public static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
|
||||
private Item item;
|
||||
|
||||
public StrorageItem(Item item) {
|
||||
public static StorageItem createItem(Item item) {
|
||||
if (item.name.equals(AGED_BRIE)){
|
||||
return new AgeddBrie(item);
|
||||
}
|
||||
return new StorageItem(item);
|
||||
}
|
||||
|
||||
public StorageItem(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@ -16,9 +26,7 @@ public class StrorageItem {
|
||||
}
|
||||
|
||||
protected void updateQuality() {
|
||||
if (item.name.equals("Aged Brie")) {
|
||||
increaseQuality();
|
||||
} else if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.name.equals(BACKSTAGE_PASSES)) {
|
||||
increaseQuality();
|
||||
|
||||
if (item.sellIn < 11) {
|
||||
@ -28,13 +36,13 @@ public class StrorageItem {
|
||||
if (item.sellIn < 6) {
|
||||
increaseQuality();
|
||||
}
|
||||
} else if (item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
} else if (item.name.equals(SULFURAS)) {
|
||||
return;
|
||||
} else decreaseQuality();
|
||||
}
|
||||
|
||||
protected void updateSelling() {
|
||||
if (item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
if (item.name.equals(SULFURAS)) {
|
||||
return;
|
||||
}
|
||||
item.sellIn--;
|
||||
@ -45,11 +53,9 @@ public class StrorageItem {
|
||||
}
|
||||
|
||||
protected void updateExpired() {
|
||||
if (item.name.equals("Aged Brie")) {
|
||||
increaseQuality();
|
||||
} else if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.name.equals(BACKSTAGE_PASSES)) {
|
||||
item.quality = 0;
|
||||
} else if (item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
} else if (item.name.equals(SULFURAS)) {
|
||||
return;
|
||||
} else {
|
||||
decreaseQuality();
|
||||
Loading…
Reference in New Issue
Block a user