It is conventional to provide concrete subclasses that return particular kinds of vehicles, such as
BusFactory,
CarFactory,
BicycleFactory, etc. However, we are going to need something just a little different. Instead, instances of this Factory will return instances of different vehicle subclasses with different frequencies. The exact percentages should be set in a constructor.
However, there should also be a
noargs constructor. For the defaults:
- Use an 80% probability of a
Car with a 10% probability of either a Bus or a Bicycle.
- Enforce a constraint that the sum of the chances of all the different vehicle types is less than or equal to 1.0 (100%) and that no single chance is less than 0% (no negative probabilities)