Part 09 / Topic 1 of 10
From one class to many
Part 7 built a single BankAccount class: one set of properties, one withdraw rule, and
deposit/withdraw functions that return a plain Boolean — true on success, false on
failure, with the reason for a failure only ever printlned, never handed back as data. That
works until a second kind of account needs a different withdrawal rule — a savings account
that must keep a minimum balance, a current account that allows going negative up to an
overdraft limit — and until a caller actually needs to know why a withdrawal failed, not just
that it did. Copy-pasting the whole class for each kind duplicates everything they share (the
account number, the holder's name, printing a statement) just to change the one rule that
differs. Kotlin's class-declaration keywords — open, interface, abstract class, sealed class, enum class, object — exist to express exactly this: what's shared, what varies, and
how much the compiler should be allowed to assume about the shape of your data.
Done here? The practice set for Part 9 — including the solutions — is on the part page.