Implementacja wzorca projektowego Fabryka w Javascript
Fabryka to kreacyjny wzorzec projektowy. Tworzymy interfejs do tworzenia instancji podklas.
class VehicleFactory {
create(type) {
if (genre === 'bike') return new Bike('Giant', 'Blue');
if (genre === 'car') return new Car('Ford', 'Black');
}
}
class Car {
constructor(brand, color) {
this.brand = brand;
this.color = color;
}
class Bike {
constructor(brand, color) {
this.brand = brand;
this.color = color;
}
}
export default VehicleFactory;