mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
- Updated Naming Conventions
This commit is contained in:
parent
5bec9bdff4
commit
b2b61a1f57
@ -7,7 +7,7 @@ public class GildedRose {
|
||||
|
||||
public func updateQuality() {
|
||||
let customFactoryObj = CustomisedItemFactory()
|
||||
_ = items.map({customFactoryObj.getCustomisedItem(item: $0).updateCustomItemQuality()})
|
||||
_ = items.map({customFactoryObj.getCustomisedItem(item: $0).updateItemState()})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,20 +7,19 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
struct AgedBrieItem: CustomisedItemProtocol, ItemSellInDaysProtocol, ItemQualityProtocol {
|
||||
struct AgedBrieItem: CustomisedItemProtocol, ItemSellInUpdater, ItemQualityUpdater {
|
||||
var item: Item
|
||||
|
||||
public init(item: Item) {
|
||||
self.item = item
|
||||
}
|
||||
|
||||
func updateCustomItemQuality() {
|
||||
func updateItemState() {
|
||||
// update the sell in days
|
||||
|
||||
reduceSellInDaysByOne(item: item)
|
||||
reduceSellInDays(for: item, by: 1)
|
||||
|
||||
// Increment the Item quality by 1 if the quality is less than 50
|
||||
guard isItemUnderHighestQuality(item: item) else {return}
|
||||
guard isItemUnderHighestQuality(item: item) else { return }
|
||||
increaseQuality(for: item, by: 1)
|
||||
}
|
||||
|
||||
|
||||
@ -7,16 +7,16 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
struct BackstagePassesItem: CustomisedItemProtocol, ItemQualityProtocol, ItemSellInDaysProtocol {
|
||||
struct BackstagePassesItem: CustomisedItemProtocol, ItemQualityUpdater, ItemSellInUpdater {
|
||||
var item: Item
|
||||
|
||||
public init(item: Item) {
|
||||
self.item = item
|
||||
}
|
||||
|
||||
func updateCustomItemQuality() {
|
||||
reduceSellInDaysByOne(item: item)
|
||||
|
||||
func updateItemState() {
|
||||
reduceSellInDays(for: item, by: 1)
|
||||
|
||||
guard !HasSellInDatePassed(item: item) else {
|
||||
setItemQualityToZero(item: item)
|
||||
return
|
||||
|
||||
@ -8,17 +8,17 @@
|
||||
import Foundation
|
||||
|
||||
protocol CustomisedItemProtocol {
|
||||
func updateCustomItemQuality()
|
||||
func updateItemState()
|
||||
}
|
||||
|
||||
|
||||
protocol ItemSellInDaysProtocol {
|
||||
func reduceSellInDaysByOne(item: Item)
|
||||
protocol ItemSellInUpdater {
|
||||
func reduceSellInDays(for item: Item, by days: Int)
|
||||
}
|
||||
|
||||
extension ItemSellInDaysProtocol {
|
||||
func reduceSellInDaysByOne(item: Item) {
|
||||
item.sellIn -= 1
|
||||
extension ItemSellInUpdater {
|
||||
func reduceSellInDays(for item: Item, by days: Int) {
|
||||
item.sellIn -= days
|
||||
}
|
||||
|
||||
func HasSellInDatePassed(item: Item) -> Bool {
|
||||
@ -26,11 +26,11 @@ extension ItemSellInDaysProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
protocol ItemQualityProtocol {
|
||||
protocol ItemQualityUpdater {
|
||||
|
||||
}
|
||||
|
||||
extension ItemQualityProtocol {
|
||||
extension ItemQualityUpdater {
|
||||
func isItemUnderHighestQuality(item: Item) -> Bool {
|
||||
return item.quality < ValueConstants.kHightestQualityValue
|
||||
}
|
||||
|
||||
@ -7,16 +7,16 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
struct StandardItem: CustomisedItemProtocol, ItemQualityProtocol, ItemSellInDaysProtocol {
|
||||
struct StandardItem: CustomisedItemProtocol, ItemQualityUpdater, ItemSellInUpdater {
|
||||
var item: Item
|
||||
|
||||
public init(item: Item) {
|
||||
self.item = item
|
||||
}
|
||||
func updateCustomItemQuality() {
|
||||
func updateItemState() {
|
||||
// Reduce the sellIn days for Item by 1
|
||||
reduceSellInDaysByOne(item: item)
|
||||
|
||||
reduceSellInDays(for: item, by: 1)
|
||||
|
||||
// Reduce the item quality by 1 , if the sell in date is passed decrement by 2
|
||||
HasSellInDatePassed(item: item) ? reduceQuality(for: item, by: decreasingValueForZeroOrLessDaysToSell()) : reduceQuality(for: item, by: decreasingValueOverZeroDaysToSell())
|
||||
guard isItemOverLowestQuality(item: item) else {
|
||||
|
||||
@ -13,7 +13,7 @@ struct SulfurasItem: CustomisedItemProtocol {
|
||||
public init(item: Item) {
|
||||
self.item = item
|
||||
}
|
||||
func updateCustomItemQuality() {
|
||||
func updateItemState() {
|
||||
// No code as there is no change in quality or sell in days of sulfuras item
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user