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() {
|
public func updateQuality() {
|
||||||
let customFactoryObj = CustomisedItemFactory()
|
let customFactoryObj = CustomisedItemFactory()
|
||||||
_ = items.map({customFactoryObj.getCustomisedItem(item: $0).updateCustomItemQuality()})
|
_ = items.map({customFactoryObj.getCustomisedItem(item: $0).updateItemState()})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,20 +7,19 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct AgedBrieItem: CustomisedItemProtocol, ItemSellInDaysProtocol, ItemQualityProtocol {
|
struct AgedBrieItem: CustomisedItemProtocol, ItemSellInUpdater, ItemQualityUpdater {
|
||||||
var item: Item
|
var item: Item
|
||||||
|
|
||||||
public init(item: Item) {
|
public init(item: Item) {
|
||||||
self.item = item
|
self.item = item
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateCustomItemQuality() {
|
func updateItemState() {
|
||||||
// update the sell in days
|
// update the sell in days
|
||||||
|
reduceSellInDays(for: item, by: 1)
|
||||||
reduceSellInDaysByOne(item: item)
|
|
||||||
|
|
||||||
// Increment the Item quality by 1 if the quality is less than 50
|
// 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)
|
increaseQuality(for: item, by: 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,16 +7,16 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct BackstagePassesItem: CustomisedItemProtocol, ItemQualityProtocol, ItemSellInDaysProtocol {
|
struct BackstagePassesItem: CustomisedItemProtocol, ItemQualityUpdater, ItemSellInUpdater {
|
||||||
var item: Item
|
var item: Item
|
||||||
|
|
||||||
public init(item: Item) {
|
public init(item: Item) {
|
||||||
self.item = item
|
self.item = item
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateCustomItemQuality() {
|
func updateItemState() {
|
||||||
reduceSellInDaysByOne(item: item)
|
reduceSellInDays(for: item, by: 1)
|
||||||
|
|
||||||
guard !HasSellInDatePassed(item: item) else {
|
guard !HasSellInDatePassed(item: item) else {
|
||||||
setItemQualityToZero(item: item)
|
setItemQualityToZero(item: item)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -8,17 +8,17 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
protocol CustomisedItemProtocol {
|
protocol CustomisedItemProtocol {
|
||||||
func updateCustomItemQuality()
|
func updateItemState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protocol ItemSellInDaysProtocol {
|
protocol ItemSellInUpdater {
|
||||||
func reduceSellInDaysByOne(item: Item)
|
func reduceSellInDays(for item: Item, by days: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ItemSellInDaysProtocol {
|
extension ItemSellInUpdater {
|
||||||
func reduceSellInDaysByOne(item: Item) {
|
func reduceSellInDays(for item: Item, by days: Int) {
|
||||||
item.sellIn -= 1
|
item.sellIn -= days
|
||||||
}
|
}
|
||||||
|
|
||||||
func HasSellInDatePassed(item: Item) -> Bool {
|
func HasSellInDatePassed(item: Item) -> Bool {
|
||||||
@ -26,11 +26,11 @@ extension ItemSellInDaysProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol ItemQualityProtocol {
|
protocol ItemQualityUpdater {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ItemQualityProtocol {
|
extension ItemQualityUpdater {
|
||||||
func isItemUnderHighestQuality(item: Item) -> Bool {
|
func isItemUnderHighestQuality(item: Item) -> Bool {
|
||||||
return item.quality < ValueConstants.kHightestQualityValue
|
return item.quality < ValueConstants.kHightestQualityValue
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,16 +7,16 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct StandardItem: CustomisedItemProtocol, ItemQualityProtocol, ItemSellInDaysProtocol {
|
struct StandardItem: CustomisedItemProtocol, ItemQualityUpdater, ItemSellInUpdater {
|
||||||
var item: Item
|
var item: Item
|
||||||
|
|
||||||
public init(item: Item) {
|
public init(item: Item) {
|
||||||
self.item = item
|
self.item = item
|
||||||
}
|
}
|
||||||
func updateCustomItemQuality() {
|
func updateItemState() {
|
||||||
// Reduce the sellIn days for Item by 1
|
// 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
|
// 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())
|
HasSellInDatePassed(item: item) ? reduceQuality(for: item, by: decreasingValueForZeroOrLessDaysToSell()) : reduceQuality(for: item, by: decreasingValueOverZeroDaysToSell())
|
||||||
guard isItemOverLowestQuality(item: item) else {
|
guard isItemOverLowestQuality(item: item) else {
|
||||||
|
|||||||
@ -13,7 +13,7 @@ struct SulfurasItem: CustomisedItemProtocol {
|
|||||||
public init(item: Item) {
|
public init(item: Item) {
|
||||||
self.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
|
// No code as there is no change in quality or sell in days of sulfuras item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user