Last active
October 26, 2021 12:28
-
-
Save AliN11/eb10fcc82074b9c983dc5904415724cc 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 Vehicle { | |
setMode(mode); | |
move(); | |
} | |
abstract class Delivery { | |
public abstract makeVehicle(): Vehicle; | |
public handle() { | |
const vehicle = this.makeVehicle(); | |
vehicle.move(); | |
} | |
} | |
class BikeDelivery extends Delivery { | |
public makeVehicle() { | |
const bike = new Bike(); | |
bike.setMode('eco'); | |
return bike; | |
} | |
} | |
class CarDelivery extends Delivery { | |
public makeVehicle() { | |
const car = new Car(); | |
car.setColor('green'); | |
return car; | |
} | |
} | |
class Bike implements Vehicle { | |
setMode(mode) {} | |
move() { | |
console.log('Moving by bike'); | |
}; | |
} | |
class Car implements Vehicle { | |
setMode(mode) {} | |
move() { | |
console.log('Moving by car'); | |
} | |
setColor(color) {} | |
} | |
const init = new CarDelivery(); | |
init.handle(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment