Interface and Abstraction in Swift5
1 min readNov 5, 2019
Swift does not support abstraction like other language.
Interface and abstraction both can achieve by Protocol.
Abstraction is useful when you want to define method for common classes. For example if multiple classes is there, and they are using similar method. In this case you can use the abstract method.
In Swift Interface can achieve by Protocol
In Swift Abstraction can achieve by Protocol-Extension
class ParentClass{
func abstractFun() {
print("This method must be overridden")
}
}
class SubClass : ParentClass {
override func abstractFunction() {
// Override
}
}