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
, applymethod
forobject
’s class with argumentsarg1
andarg2
- Form:
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