Learning Kotlin and Swift

Kotlin vs Swift: The Abstract Class

Explore Kotlin and Swift together and learn their differences

Photo by JJ Ying on Unsplash

In Mobile development, the 2 major programming language to learn is Swift and Kotlin. They look very similar, sometimes one feature is available in one language but not the other one. Nonetheless, there are workaround it.

One good example is the Abstract Class.

Abstract class

In Kotlin, we can have an abstract class (e.g. something in between a class and interface, where it enforce some of its variable or function being set, but can still store its own state.

In Swift, there is no abstract class but uses protocol to imitate it, together with the help of class extension.

In Kotlin

Below is a simple example of an abstract class with

  • an overridable variable something (override by the child)
  • an overridable function doSomething (override by the child)
  • a state variable stateVariable
  • a local function baseLocalFunction
abstract class Base(private val stateVariable: String) {
abstract val abstractVariable: String
abstract…

--

--