'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
getCalculatormethod that takes a non-nullCalculatorTypeargument with aDEFAULTCalculatorTypeenum value - A
getSpecificCalculatormethod that takes a non-nullCalculatorTypeargument (noDEFAULTCalculatorTypeenum value), as well as agetDefaultCalculatormethod that takes no arguments - A
getCalculatormethod that takes a non-nullOptional<CalculatorType>argument (noDEFAULTCalculatorTypeenum 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 |
|---|
