AbstractClass: Create an abstract R6 Class

Description Details References Examples

View source: R/AbstractClass.R

Description

Creates an abstract R6 class by placing a thin wrapper around R6::R6Class which causes an error to be thrown if the class is directly constructed instead of one of its descendants.

Details

An abstract class is a class that cannot be constructed directly. Instead they are used to define common fields/methods for child classes that inherit from them.

All arguments of R6::R6Class can be used as usual, see full details at R6::R6Class.

References

Gamma, E., Helm, R., Johnson, R., & Vlissides, J. (1996). Design Patterns: Elements of Reusable Software. Addison-Wesley Professional Computing Series (p. 395).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(R6)

ab <- AbstractClass("abstract", public = list(hello = "Hello World"))
## Not run: 
# errors
ab$new()

## End(Not run)
child <- R6Class("child", inherit = ab)
child$new()$hello

ooplah documentation built on Jan. 21, 2022, 5:07 p.m.