Skip to content

Instantly share code, notes, and snippets.

@kaeff
Created March 18, 2021 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaeff/e9bacc3a340830ab5b82b89691a7a681 to your computer and use it in GitHub Desktop.
Save kaeff/e9bacc3a340830ab5b82b89691a7a681 to your computer and use it in GitHub Desktop.
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