Everything else is just a tool to model your domain in a way that’s easier to read and reason about, and to produce much shorter code. Interfaces define module boundaries and can be mocked to enable simpler testing. Through classes, objects, and data structures, you can model your domain entities. Enums make a list of limited options crystal clear. Extensions allow you to add functionality to existing types, without having access to their original source code, giving advantage of better logic structure. With generics, you can write universal code, promoting reuse. And overloaded operators give that extra edge to common operations that benefit from succinct, crisp syntax.

Object types (classes)

Custom types that focus on behavior. Object types allow you to model your domain, so you can reason about it more easily. You can give things familiar names, group properties and operations, define relationships, and form as many layers of abstraction as you like. These are subjective representations of the author’s imagination. Oftentimes quite useful, as we are used to think in models of the world.

Abstract classes

Given the possibility of inheritance, you can also write base classes that feature only partial implementation and must be specialized to be useful. The so-called abstract classes define an interface with some implementation, but they can’t be instantiated on their own.

Normally, you would use interfaces for your base as they also support default implementation of methods and computed properties, but abstract classes come into play when you need: common stored properties, to restrict overriding, or an instance reference for an inner class.

open class TextShape {
  open fun draw() = """
  =====================
  |                   |
  |  XXXXXXXXXXXXXXX  |
  |                   |
  =====================
  """
}

abstract class EmojiTextShape: TextShape() {
  abstract override fun draw(): String

  abstract val length: Int

  inner class FramedShape {
    fun drawFramed(): String {
      return super@EmojiTextShape.draw()
        .replace("XXXXXXXXXXXXXXX", draw())
    }
  }
}

class ThumbsUpTextShape: EmojiTextShape() {
  override fun draw() = "ദ്ദി(˵ •̀ ᴗ - ˵ ) ✧"

  override val length: Int
    get() = draw().length
}

[--]