-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesignPattern.js
More file actions
32 lines (27 loc) · 844 Bytes
/
designPattern.js
File metadata and controls
32 lines (27 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function Car(num_of_wheels, num_of_passengers, has_gas) {
this.num_of_wheels = num_of_wheels;
this.num_of_passengers = num_of_passengers;
this.has_gas = has_gas;
this.type = "Car";
}
function Plane(num_of_wheels, num_of_passengers, has_gas) {
this.num_of_wheels = num_of_wheels;
this.num_of_passengers = num_of_passengers;
this.has_gas = has_gas;
this.type = "Plane";
}
function VehicleFactory() {
this.create = (wheels, passengers, gas, type) => {
switch (type) {
case 1:
return new Car(wheels, passengers, gas);
case 2:
return new Plane(wheels, passengers, gas);
}
};
}
const vehicleFactory = new VehicleFactory();
const vehicles = [];
vehicles.push(vehicleFactory.create(4, 10, true, 1));
vehicles.push(vehicleFactory.create(5, 20, true, 2));
module.exports = { VehicleFactory };