Effective Kotlin: Item 23 — Prefer class hierarchies to tagged classes

Tagged classes as discussed in item 23 of Joshua Bloch’s famous book, Effective Java, are classes that contain a tag field indicating the flavour of the instance. For example, a Shape class may have a tag field to denote if it’s a Rectangle or a Circle with methods such as area using switch statements. Often these styles of classes can be re-written as a class hierarchy with an abstract parent containing any shared functionality and abstract methods.