Interface and Abstraction in Swift5

Divesh Singh
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
}
}

--

--

Divesh Singh
Divesh Singh

Written by Divesh Singh

Postgraduate from JEC Jabalpur || iOS and macOS developer, traveler |||| EM at Darwinbox | Ex-Samsung || Ex - Optimize IT Sys | Ex - R Systems