Coming from languages like Java/C++ we are used to partial or abstract class implementations e.g.
protocol ProtocolA {
func x()
func y()
}
// attempt to partially implement ProtocolA
class AbstractProtocolA: ProtocolA {
func x() { /* implementation */ }
// does not implement function y
}
class ConcreteA1: AbstractProtocolA {
func y() { /* implementation */ }
}
class ConcreteA2: AbstractProtocolA {
override func x() { /* implementation */ }
func y() { /* implementation */ }
}
but this is not possible in Swift, in this case I would get the compilation error Type 'AbstractProtocolA' does not conform to protocol 'ProtocolA' ... is there another Swifty way to cover this OOD use-case?
UPDATE: A way to circumvent this limitation would be to:
enum ProtocolAError: ErrorType {
case NotImplementedException(methodName: String)
}
class AbstractProtocolA: ProtocolA {
func x() { /* implementation */ }
func y() { throw ProtocolAError.NotImplementedException(methodName: "y") }
}
but here we shift design/programming mistakes (i.e. instantiating the abstract AbstractProtocolA) to runtime rather than compile time.
optionalkeyword?