12.4 OOP in R: Two Paradigms

1. Encapsulated OOP

  • Objects “encapsulate”
    • Methods (i.e., what can be done)
    • Fields (i.e., data on which things are done)
  • Calls communicate this encapsulation, since form follows function
    • Form: object.method(arg1, arg2)
    • Function: for object, apply method for object’s class with arguments arg1 and arg2

2. Functional OOP

  • Methods belong to “generic” functions
  • From the outside, look like regular functions: generic(object, arg2, arg3)
  • From the inside, components are also functions

12.4.1 Concept Map

Mermaid code
DiagrammeR::mermaid("
graph LR

OOP --> encapsulated_OOP
OOP --> functional_OOP

functional_OOP --> S3
functional_OOP --> S4

encapsulated_OOP --> R6
encapsulated_OOP --> RC
")