Preferring sealed classes over enums
Coming from Java, you may be tempted to overload your enum
with functionality.
For example, let's say you build an application that allows users to order a pizza and track its status. We can use the following code for this:
// Java-like code that uses enum to represent State enum class PizzaOrderStatus { ORDER_RECEIVED, PIZZA_BEING_MADE, OUT_FOR_DELIVERY, COMPLETED; fun nextStatus(): PizzaOrderStatus { return when (this) { ORDER_RECEIVED -> PIZZA_BEING_MADE PIZZA_BEING_MADE -> OUT_FOR_DELIVERY OUT_FOR_DELIVERY -> COMPLETED ...