Created
May 16, 2017 12:50
-
-
Save getdave/19cd9969d6ff9145073b5a16972527b5 to your computer and use it in GitHub Desktop.
Example of Classical Inheritance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Appliance { | |
turnOn() { | |
console.log(this.type + " now online"); | |
} | |
} | |
class Oven extends Appliance { | |
constructor() { | |
this.type = "Oven"; | |
} | |
setTemperature(temp) { | |
console.log("Temp set to ${temp}"); | |
} | |
} | |
class Radio extends Appliance { | |
constructor() { | |
this.type = "Radio"; | |
} | |
setChannel(channel) { | |
console.log("Now listening to channel ${temp}"); | |
} | |
} | |
$oven_1 = new Oven(); | |
// Inherited functionality | |
$oven_1->turnOn(); // --> "Oven now online" | |
$oven_1->setTemperature(100); // --> "Temp set to 100" | |
$radio = new Radio(); | |
// Inherited functionality | |
$radio->turnOn() // --> "Radio now online" | |
$radio->setChannel(5); // --> "Now listening to channel 5" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment