Specifying a Fancy Microwave Oven
Inheritance is used to propagate—that is, copy—functionality from one class to another. To create a child class from another class, use the inherit argument to R6Class() (docs).
The pattern to create a child class is:
child_class_factory <- R6Class(
"ChildClass",
inherit = parent_class_factory
)
यह अभ्यास पाठ्यक्रम का हिस्सा है
Object-Oriented Programming with S3 and R6 in R
अभ्यास निर्देश
A microwave oven class has been defined for you in the variable microwave_oven_factory.
- Create a
FancyMicrowaveOvenclass that inherits fromMicrowaveOven.- Call
R6Class()(docs). - The
classnameargument should be"FancyMicrowaveOven". - The
inheritargument should bemicrowave_oven_factory. - Assign this to the variable
fancy_microwave_oven_factory. Do not add any extra functionality yet.
- Call
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Explore the microwave oven class
microwave_oven_factory
# Define a fancy microwave class inheriting from microwave oven
fancy_microwave_oven_factory <- ___