BankAccount <- R6Class("BankAccount", public = list(
owner = NULL,
type = NULL,
balance = 0,
initialize = function(owner, type, acct_num = NULL) {
private$acct_num <- acct_num
self$owner <- owner
self$type <- type
},
deposit = function(amount) {
self$balance <- self$balance + amount
invisible(self)
},
withdraw = function(amount) {
self$balance <- self$balance - amount
invisible(self)
},
print = function(...) {
cat("Account owner: ", self$owner, "\n", sep = "")
cat("Account type: ", self$type, "\n", sep = "")
cat("Account #: ", private$acct_num, "\n", sep = "")
cat(" Balance: ", self$balance, "\n", sep = "")
invisible(self)
}
),
private = list(
acct_num = NULL
),
active = list(
create_acct_num = function(value) {
if (is.null(private$acct_num)) {
private$acct_num <- ids::uuid()
} else {
stop("`$acct_num` already assigned")
}
}
)
)