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
2
Q
A