R has three object oriented (OO) systems: [[S3]], [[S4]] and [[R5]]. This page describes S4.
Compared to S3, the S4 object system is much stricter, and much closer to other OO systems. I recommend you familiarise yourself with the way that [[S3]] works before reading this document - many of underlying ideas are the same, but the implementation is much stricter. There are two major differences from S3:
formal class definitions: unlike S3, S4 formally defines the representation and inheritance for each class
multiple dispatch: the generic function can be dispatched to a method based on the class of any number of argument, not just one
Here we introduce the basics of S4, trying to stay away from the esoterica and focussing on the ideas that you need to understand and write the majority of S4 code.
|