Often I find a need for designing objects with custom functionality.
To demonstrate, suppose I create a DateIterator . Configurable options can be whether to iterate a closed interval [start, end] or an open interval [start, end) .
- (1) In my opinion, an indecent solution limited to only one true / false configuration parameter
new DateIterator(boolean openInterval);
- (2) A typical enumeration method is usually a bit cumbersome
new DateIterator(Interval.OPEN_END);
- (3) An unconventional attempt is good, but not too direct.
new DateIterator().openEnd();
- (4) The inheritance approach - often over-engineering
new OpenEndedDateIterator();
For this, several alternatives arise that I consider incomplete, for example, the integer-based configuration new DateIterator(Interval.OPEN_END); or property based configuration.
Are there any other approaches? Which approach do you prefer?
java parameter-passing design configuration
Johan sjöberg
source share