1 Introduction

There are two main styles of Object-Oriented Programming (OOP) - message passing OOP and - generic function OOP.

Although message passing OOP is can be found in more programming languages in R the generic function OOP is more often used than the message passing OOP style.

1.1 Message-Passing

In OOP message passing describes that a message, i.e. the name of the method and its input parameters, it passed to the object for dispatch.

1.2 Generic-Function

Generic functions, also known as polymorphic functions, are functions whose implementation varies based on the types of its arguments. In other words, the code executed for a specific set of arguments is determined by the types of those arguments.

1.3 Why OOP is usefull?

  • Support structural thinking (numeric vectors, factors, data frames, results of fitting a model, …)
  • Support functional thinking (generic functions)
  • Allow for simple extensibility (printing, plotting, summarizing, …)

1.4 OOP in R

There exist several OOP implementations in R

  • S3 classes
  • S4 classes
  • Reference classes
  • R6 classes
  • S7 classes

2 Examples

The examples will be shown during the lecture.

3 References