Last active
December 19, 2021 08:16
-
-
Save msankhala/c469f2ccb4f4969d54e03001fae7d24c to your computer and use it in GitHub Desktop.
Factor pattern js pattern
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
import Motorvehicle from './Motorvehicle'; | |
import Aircraft from './Aircraf'; | |
import Railvehicle from './Railvehicle'; | |
const VehicleFactory = (type, make, model, year) => { | |
if (type === car) { | |
return new Motorvehicle('car', make, model, year); | |
} else if (type === airplane) { | |
return new Aircraft('airplane', make, model, year); | |
} else if (type === helicopter) { | |
return new Aircraft('helicopter', make, model, year); | |
} else { | |
return new Railvehicle('train', make, model, year); | |
} | |
} | |
module.exports = VehicleFactory; | |
const audiAllRoad = VehicleFactory('car', 'Audi', 'A6 Allroad', '2020'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment