Expr() class Sum(val left: Expr, val right: Expr) : Expr() restricts class hierarchy: all subclasses must be located in the same file fun eval(e: Expr): Int = when (e) { is Num -> e.value is Sum -> eval(e.left) + eval(e.right) }
} interface Logger { fun logAll() } class Controller( repository: Repository, logger: Logger ) : Repository by repository, Logger by logger fun use(controller: Controller) { controller.logAll() } Class delegation