Design Patterns Flashcards

1
Q

Factory Method Pattern
<br></br>
Implement the Factory Method design pattern.
<br></br>
Example:
<br></br>
```Java
VehicleFactory carFactory = new CarFactory();
VehicleFactory truckFactory = new TruckFactory();
VehicleFactory bikeFactory = new BikeFactory();

Vehicle myCar = carFactory.createVehicle();
Vehicle myTruck = truckFactory.createVehicle();
Vehicle myBike = bikeFactory.createVehicle();

myCar.getType(); // “Car”
myTruck.getType(); // “Truck”
myBike.getType(); // “Bike”
~~~

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly