Created
March 18, 2021 19:02
-
-
Save kaeff/e9bacc3a340830ab5b82b89691a7a681 to your computer and use it in GitHub Desktop.
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 Car { | |
this.engine; | |
ignite() { | |
this.engine.turnOn(); | |
} | |
accelerate() {} | |
getPostiion() {} | |
turnLeft() {} | |
turnOff() { | |
this.engine.turnOff(); | |
} | |
} | |
class Driver { | |
constructor(car) { | |
this.car = car; | |
} | |
driveTo(destination) { | |
this.car.ignite(); | |
this.car.accelerate(); | |
let atDestination = false; | |
while (!atDestination) { | |
this.turnLeft(); | |
atDestination = car.getPostiion() === destination; | |
} | |
this.car.turnOff(); | |
} | |
} | |
const yellowNycTaxi = new Car(); | |
const taxiDriver = new Driver(yellowNycTaxi); | |
taxiDriver.driveTo('mac donalds') | |
taxiDriver.driveTo('home') | |
const londonCab = Car(); | |
const anotherDriver = new Driver(londonCab); | |
anotherDriver.driveTo('home') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment