Investigate: Why is ConsistencyMode a class instead of an enum? #320
Replies: 1 comment
-
This commit was made in January 2020, and it is now August 2023. I was only using the library at that point when it was maintained by Rick Fast. It appears that the main reason it was changed from an enum to a class was to allow the "additional headers" as mentioned in the commit message:
It is true that this would not be possible with an enum, but maybe this could have been done by introducing a separate enum class. The static factory method public class ConsistencyMode {
private final String name;
private final ConsulConsistencyMode consulConsistencyMode;
private final String param;
private final private final Map<String, String> additionalHeaders;
// constructors and/or factory methods, builder, getters, etc.
}
public enum ConsulConsistencyMode {
DEFAULT, STALE, CONSISTENT
} In the above, However, Another possible (now that we’re on JDK 17) design might be to make As a side note, all usages of the But assuming this stays as a class, does it really need to pretend to be like an enum? Or can the “enum-like” methods and behavior such as |
Beta Was this translation helpful? Give feedback.
-
The
ConsistencyMode
class looks very much like an enum, and even replicates the behavior of enums, e.g. it definesname()
,ordinal()
, andvalues()
methods. Hopefully there is some clue in the git commit history.Beta Was this translation helpful? Give feedback.
All reactions