Making a Fancy Microwave Oven
Inheritance means that the methods of the child class are exact copies of those in the parent class.
Diese Übung ist Teil des Kurses
Object-Oriented Programming with S3 and R6 in R
Anleitung zur Übung
A microwave oven and and fancy microwave oven have been predefined in your workspace.
- Instantiate a regular microwave oven and a fancy microwave oven, assigning the values to
a_microwave_oven
anda_fancy_microwave
respectively. - Get the
power_rating_watts
value for each type of microwave, assigning the values tomicrowave_power_rating
andfancy_microwave_power_rating
respectively. - Use
identical()
(docs) to verify that the two power ratings are the same. - Call the
cook()
method of each type of microwave for one second and observe that you get the same behavior in each case.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Explore microwave oven classes
microwave_oven_factory
fancy_microwave_oven_factory
# Instantiate both types of microwave
a_microwave_oven <- ___
a_fancy_microwave <- ___
# Get power rating for each microwave
microwave_power_rating <- ___
fancy_microwave_power_rating <-___
# Verify that these are the same
identical(___, ___)
# Cook with each microwave
___
___