14.12 Inheritance
- To inherit behaviour from an existing class, provide the class object via the
inherit
argument. - This example also provides a good example on how to debug an R6 class.
BankAccountOverDraft <- R6Class("BankAccountOverDraft",
inherit = BankAccount,
public = list(
withdraw = function(amount) {
if ((self$balance - amount) < 0) {
stop("Overdraft")
}
# self$balance() <- self$withdraw()
self$balance <- self$balance - amount
invisible(self)
}
)
)