February 2018
Intermediate to advanced
350 pages
7h 35m
English
So far, so good. Our bakery looks good. However, we have a problem with our current model. Let's look at the following code:
fun main(args: Array<String>) { val anyGood = BakeryGood("Generic flavour")}
We can instantiate the BakeryGood class directly, which is too generic. To correct this situation, we can mark BakeryGood as abstract:
abstract class BakeryGood(val flavour: String) { fun eat(): String { return "nom, nom, nom... delicious $flavour ${name()}" } open fun name(): String { return "bakery good" } }
An abstract class is a class designed solely to be extended. An abstract class can't be instantiated, which fixes our problem.
What makes abstract different from open?
Both modifiers let us extend a class, but ...
Read now
Unlock full access