Skip to content

Instantly share code, notes, and snippets.

@clementohNZ
Created October 25, 2019 02:57
Show Gist options
  • Save clementohNZ/f4c05e74759ea92af9ca102e12b85a7f to your computer and use it in GitHub Desktop.
Save clementohNZ/f4c05e74759ea92af9ca102e12b85a7f to your computer and use it in GitHub Desktop.

Revisions

  1. clementohNZ created this gist Oct 25, 2019.
    45 changes: 45 additions & 0 deletions liskov-1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    class Car {
    constructor() {
    this.distance = 0;
    }

    move() {
    this.distance += 1;
    console.log(`current distance is: ${this.distance}`);
    }
    }

    class Toyota extends Car {
    constructor() {
    super();
    }

    move() {
    super.move();
    }
    }

    class Ferrari extends Car {
    constructor() {
    super();
    }

    moveVeryQuickly() {
    this.distance += 5;
    console.log(`current distance is: ${this.distance}`);
    }
    }


    const cars = [
    new Car(),
    new Toyota(),
    new Ferrari(),
    ]

    cars.forEach(car => {
    car.move();
    });
    // current distance is: 1
    // current distance is: 1
    // current distance is: 1