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()
|
||||
}
|
||||
|
||||
class CustomisedItemFactory {
|
||||
protocol CustomisedItemFactoryCreator {
|
||||
static func getCustomisedItem(item: Item) -> CustomisedItem
|
||||
}
|
||||
|
||||
|
||||
struct CustomisedItemFactory: CustomisedItemFactoryCreator {
|
||||
// Returns the Customised Item based on the Item name
|
||||
func getCustomisedItem(item: Item) -> CustomisedItem {
|
||||
static func getCustomisedItem(item: Item) -> CustomisedItem {
|
||||
switch item.name {
|
||||
case ItemNameConstants.kAgedBrieItem:
|
||||
return AgedBrieItem(item: item)
|
||||
@ -27,7 +32,3 @@ class CustomisedItemFactory {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ public class GildedRose {
|
||||
}
|
||||
|
||||
public func updateQuality() {
|
||||
let customFactoryObj = CustomisedItemFactory()
|
||||
_ = items.map({customFactoryObj.getCustomisedItem(item: $0).updateItemState()})
|
||||
_ = items.map({CustomisedItemFactory.getCustomisedItem(item: $0).updateItemState()})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user