Get startedGet started for free

Over-Overriding the Cooking Capabilities

Once intermediate classes have exposed their parent functionality with super_ active bindings, you can access methods across several generations of R6 class. The syntax is

parent_method <- super$method()
grand_parent_method <- super$super_$method()
great_grand_parent_method <- super$super_$super_$method()

This exercise is part of the course

Object-Oriented Programming with S3 and R6 in R

View Course

Exercise instructions

Microwave oven and fancy microwave oven classes have been predefined for you in your workspace. A string ascii_pizza_slice has also been predefined.

  • Explore the other microwave oven factories by printing their names.
  • Define a HighEndMicrowaveOven class generator using R6Class() (docs), and assign it to high_end_microwave_oven_factory.
    • It should inherit from FancyMicrowaveOven.
    • It should have a public list element.
  • Override the public cook() method.
    • The method should take a single argument named time_seconds.
    • It should call the MicrowaveOven's cook() method, …
    • then display a pizza slice using message(ascii_pizza_slice) (docs).
  • Instantiate a high-end microwave oven object and assign it to a_high_end_microwave.
  • Call a_high_end_microwave's cook() method to cook for one second.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Explore other microwaves
microwave_oven_factory
fancy_microwave_oven_factory

# Define a high-end microwave oven class
high_end_microwave_oven_factory <- ___(
 "___",
  ___ = ___,
  ___ = ___(
    ___ = ___
    
    
    
  )
)

# Instantiate a high-end microwave oven
a_high_end_microwave <- ___

# Use it to cook for one second
___
Edit and Run Code