October 2018
Intermediate to advanced
370 pages
9h 15m
English
Sealed classes are designed for situations in which a limited set of functionalities are required and no other class is allowed to be part of this set. For example, let's say we are writing an application for an order-delivery service in which a limited number of steps are involved:
Let's create an Order class with the item property:
class Order(val item : String)
Create a sealed class, OrderDelivery, with one property, Order. We then need to create three child classes, each of which represents one of the steps:
sealed class OrderDelivery(val order : Order) class ReceivedAtDepot(val depotName : String, ...
Read now
Unlock full access