• Category: creational
  • Type: object
  • Motivation: use factory object to create an object instead of repeating creation logic everywhere

do {
    let doorFactory = DoorFactory()
    let door = doorFactory.makeDoor()
    print("WoodenDoor: \(door.width) \(door.height)")
}
protocol Door
{
    var width: Int { get set }
    var height: Int { get set }
}

class WoodenDoor: Door
{
    var width: Int
    var height: Int

    init(width: Int, height: Int) {
        self.width = width
        self.height = height
    }
}
class DoorFactory
{
    func makeDoor() -> Door
    {
        return WoodenDoor(width: 100, height: 100)
    }
}