Finally introducing users with S3 classes
Our object-oriented system is almost finalized. We're only missing the User
definition. In this case, we will use S3 to define the User
class. The user_constructor()
function takes an email
and a Storage
instance in storage
to create a User
instance. However, before it does, it checks that the email is valid with the valid_email()
function defined below. After the user has been created, the get_wallets()
method is called upon it to get the wallets associated to the user before it's sent back.
The valid_email()
function simply receives a string which is supposed to be an email address, and checks whether at least one @
and one .
symbol are contained within it. Of course, this is not a robust mechanism to check whether or not it's an email address, and it's put here just to illustrate how a checking mechanism could be implemented:
source("../assets/wallets/wallet.R", chdir = TRUE) user_constructor <- function(email, storage) { if (!valid_email...