- Creating a Protocol for Factory Method

This commit is contained in:
Manali Mogre 2020-08-17 20:49:39 +02:00
parent db0db19d5d
commit bf62bf2ceb
2 changed files with 8 additions and 8 deletions

View File

@ -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 {
}
}
}

View File

@ -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()})
}
}