Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 227
Note – Assigning in the encapsulating environment
ОглавлениеNotice that, the assignment operator within an object is the local assignment operator: <<-
. The operator <<-
will call the accessor functions if defined (via the object$accessors()
function).
We can now create accounts and use the methods supplied.
ph_acc <- currAccount$new(ref_number = 321654987, holder = “Philippe”, branch = “LDN05”, opening_date = as.Date(Sys.Date()), account_type = “current”, interest_rate = 0.01, balance = )
Now, we can start using the money and withdrawing money.
ph_acc$balance # after creating balance is 0: ## [1] 0 ph_acc$debet(200) # impossible (not enough balance) ## Error in ph_acc$debet(200): Not rich enough! ph_acc$credit(200) # add money to the account ph_acc$balance # the money arrived in our account ## [1] 200 ph_acc$debet(100) # this is possible ph_acc$balance # the money is indeed gone ## [1] 100