'Using Optional Enum as a method argument

Let's say there is some CalculatorFactory that returns specific calculators based on a CalculationType enum.

Let's also say that there is a requirement for some default behavior if a specific CalculatorType is not defined.

What are the tradeoffs between the following interfaces for this CalculatorFactory:

  • A getCalculator method that takes a non-null CalculatorType argument with a DEFAULT CalculatorType enum value
  • A getSpecificCalculator method that takes a non-null CalculatorType argument (no DEFAULT CalculatorType enum value), as well as a getDefaultCalculator method that takes no arguments
  • A getCalculator method that takes a non-null Optional<CalculatorType> argument (no DEFAULT CalculatorType enum value)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source