6.1 Two types of OOP system

6.1.1 Encapsulated OOP

6.1.2 Generic function OOP

6.2 S3

6.2.1 Behind the generics

As we mentioned above, in S3, methods belong to function, which is called generic functions.

If a call to UseMethod() can be found in the source code of a function, then this function is a generic function. It is the function that figures out the correct method to call, the process of method dispatch.

>>> mean
function (x, ...)
UseMethod("mean")
<bytecode: 0x127f01628>
<environment: namespace:base>

What the generic function really does is to find and call a function named <generic>.<class> according to the class of the input. For example, Date method for the mean() generic is called mean.Date().

6.2.2 Testing generics