mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Add objects
This commit is contained in:
parent
78610c31c5
commit
97a96bb1e2
18
Java/src/main/java/com/gildedrose/BackstagePassesItem.java
Normal file
18
Java/src/main/java/com/gildedrose/BackstagePassesItem.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class BackstagePassesItem {
|
||||
public static void handleDay(Item item) {
|
||||
// todo: make it so these items can't be initialized with over 50
|
||||
if (item.quality == 50) {
|
||||
return;
|
||||
}
|
||||
if (item.sellIn == 0) {
|
||||
item.quality = 0;
|
||||
} else if (item.sellIn <= 5) {
|
||||
item.quality += 3;
|
||||
} else if (item.sellIn <= 10) {
|
||||
item.quality += 2;
|
||||
}
|
||||
item.sellIn -= 1;
|
||||
}
|
||||
}
|
||||
14
Java/src/main/java/com/gildedrose/GenericItem.java
Normal file
14
Java/src/main/java/com/gildedrose/GenericItem.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class GenericItem {
|
||||
public static void handleDay(Item item) {
|
||||
item.sellIn -= 1;
|
||||
if (item.quality == 0) {
|
||||
return;
|
||||
}
|
||||
if (item.sellIn < 0) {
|
||||
item.quality -= 1;
|
||||
}
|
||||
item.quality -= 1;
|
||||
}
|
||||
}
|
||||
@ -27,41 +27,15 @@ class GildedRose {
|
||||
handleSulfuras(item);
|
||||
return;
|
||||
case BACKSTAGE_PASSES:
|
||||
handleBackstagePasses(item);
|
||||
BackstagePassesItem.handleDay(item);
|
||||
return;
|
||||
default:
|
||||
handleGenericItem(item);
|
||||
GenericItem.handleDay(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleGenericItem(Item item) {
|
||||
item.sellIn -= 1;
|
||||
if (item.quality == 0) {
|
||||
return;
|
||||
}
|
||||
if (item.sellIn < 0) {
|
||||
item.quality -= 1;
|
||||
}
|
||||
item.quality -= 1;
|
||||
}
|
||||
|
||||
private static void handleBackstagePasses(Item item) {
|
||||
// todo: make it so these items can't be initialized with over 50
|
||||
if (item.quality == 50) {
|
||||
return;
|
||||
}
|
||||
if (item.sellIn == 0) {
|
||||
item.quality = 0;
|
||||
} else if (item.sellIn <= 5) {
|
||||
item.quality += 3;
|
||||
} else if (item.sellIn <= 10) {
|
||||
item.quality += 2;
|
||||
}
|
||||
item.sellIn -= 1;
|
||||
}
|
||||
|
||||
private static void handleSulfuras(Item item) {
|
||||
|
||||
}
|
||||
|
||||
private static void handleAgedBrie(Item item) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user