Created
December 1, 2015 14:28
-
-
Save kennycoder/cbaaf89a37f085bd278c to your computer and use it in GitHub Desktop.
This file contains 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
interface IVehicle { | |
start(type: string): string; | |
} | |
interface ITrunk { | |
openTrunk(): void | |
} | |
interface IWindow { | |
openWindow(): void | |
} | |
class Vehicle implements IVehicle { | |
private color: string; | |
constructor(color: string) { | |
this.color = color; | |
} | |
start(type: string) { | |
return 'The ' + this.color + ' ' + type + ' started'; | |
} | |
} | |
class Car extends Vehicle { | |
constructor(color: string) { | |
super(color); | |
} | |
start() { | |
return super.start('car'); | |
} | |
} | |
class Sedan extends Car implements ITrunk, IWindow { | |
constructor(color: string) { | |
super(color); | |
} | |
start() { | |
return super.start() + ' and it is a Sedan'; | |
} | |
openTrunk() { | |
console.log('Trunk is open'); | |
} | |
openWindow() { | |
console.log('Window is open'); | |
} | |
} | |
class Truck extends Vehicle { | |
constructor(color: string) { | |
super(color); | |
} | |
start() { | |
return super.start('truck'); | |
} | |
} | |
var car = new Car('green'); | |
var sedan = new Sedan('red'); | |
sedan.openTrunk(); | |
sedan.openWindow(); | |
var truck = new Truck('blue'); | |
console.log(car.start()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment