new_greeting <- function() {
structure(list(), class = "Greeting")
}
# 对象是唯一的参数
say_goodbye <- function(greeting) {
UseMethod("say_goodbye")
}
say_goodbye.Greeting <- function(greeting) {
cat("Goodbye!\n")
}
# 完全没有参数:就是普通函数
say_hello <- function() {
cat("Hello!\n")
}
greeting <- new_greeting()
say_goodbye(greeting)
say_hello()