Pemrograman Berorientasi Objek dengan S3 dan R6 di R
Richie Cotton
Data Evangelist at DataCamp
thing_factory <- R6Class(
"Thing",
public = list(
do_something = function() {
message("the parent do_something method")
}
)
)
child_thing_factory <- R6Class( "ChildThing", inherit = thing_factory,public = list( do_something = function() { message("the child do_something method") },do_something_else = function() { message("the child do_something_else method") }))
a_child_thing <- child_thing_factory$new()
a_child_thing$do_something()
the child do_something method
private$ mengakses field privat
self$ mengakses metode publik di self
super$ mengakses metode publik di parent
child_thing_factory <- R6Class( "ChildThing", inherit = thing_factory, public = list( do_something = function() { message("the child do_something method") }, do_something_else = function() { message("the child do_something_else method")self$do_something()super$do_something()} ) )
a_child_thing <- child_thing_factory$new()
a_child_thing$do_something_else()
the child do_something_else method
the child do_something method
the parent do_something method
self$ mengakses metode publik di selfsuper$ mengakses metode publik di parentPemrograman Berorientasi Objek dengan S3 dan R6 di R