new_greeting <- function() {
structure(list(), class = "Greeting")
}
# The object is the only parameter
say_goodbye <- function(greeting) {
UseMethod("say_goodbye")
}
say_goodbye.Greeting <- function(greeting) {
cat("Goodbye!\n")
}
# No parameters at all: a plain function
say_hello <- function() {
cat("Hello!\n")
}
greeting <- new_greeting()
say_goodbye(greeting)
say_hello()