What is Object-Oriented Programming?

Object-Oriented Programming with S3 and R6 in R

Richie Cotton

Data Evangelist at DataCamp

ch1_1-what-is-oop.003.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.004.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.005.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.006.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.007.png

                    <- function(       ) {


}
Object-Oriented Programming with S3 and R6 in R

function

ch1_1-what-is-oop.007.png

calculate_something  <- function(       ) {
  # do something

}
Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.010.png

calculate_something  <- function(x,  y, z) {
  # do something

}
Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.012.png

calculate_something  <- function(x,  y, z) {
  # do something
  return(the_result)
}
Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.014.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.015.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.016.png

Object-Oriented Programming with S3 and R6 in R

 

 

 

A method is just a function, talked about in an OOP context

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.019.png

Object-Oriented Programming with S3 and R6 in R

 

 

list

 

 

environment

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.024.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.026.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.028.png

Object-Oriented Programming with S3 and R6 in R

 

Tidyverse logo.   dplyr logo.

Object-Oriented Programming with S3 and R6 in R

 

 

When is OOP a good idea?

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.034.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.036.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.038.png

Object-Oriented Programming with S3 and R6 in R

ch1_1-what-is-oop.040.png

Object-Oriented Programming with S3 and R6 in R

Summary

  • With functional programming, think about the functions first.
  • With object-oriented programming (OOP) think about the data structures first.
  • Don't use OOP for general purpose data analyses.
  • Do use OOP when you have a limited number of complex objects.
Object-Oriented Programming with S3 and R6 in R

Let's practice!

Object-Oriented Programming with S3 and R6 in R

Preparing Video For Download...