mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
- Creating a Protocol for Factory Method
This commit is contained in:
parent
db0db19d5d
commit
bf62bf2ceb
@ -12,9 +12,14 @@ protocol CustomisedItem {
|
|||||||
func updateItemState()
|
func updateItemState()
|
||||||
}
|
}
|
||||||
|
|
||||||
class CustomisedItemFactory {
|
protocol CustomisedItemFactoryCreator {
|
||||||
|
static func getCustomisedItem(item: Item) -> CustomisedItem
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct CustomisedItemFactory: CustomisedItemFactoryCreator {
|
||||||
// Returns the Customised Item based on the Item name
|
// Returns the Customised Item based on the Item name
|
||||||
func getCustomisedItem(item: Item) -> CustomisedItem {
|
static func getCustomisedItem(item: Item) -> CustomisedItem {
|
||||||
switch item.name {
|
switch item.name {
|
||||||
case ItemNameConstants.kAgedBrieItem:
|
case ItemNameConstants.kAgedBrieItem:
|
||||||
return AgedBrieItem(item: item)
|
return AgedBrieItem(item: item)
|
||||||
@ -27,7 +32,3 @@ class CustomisedItemFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,6 @@ public class GildedRose {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func updateQuality() {
|
public func updateQuality() {
|
||||||
let customFactoryObj = CustomisedItemFactory()
|
_ = items.map({CustomisedItemFactory.getCustomisedItem(item: $0).updateItemState()})
|
||||||
_ = items.map({customFactoryObj.getCustomisedItem(item: $0).updateItemState()})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user