Consider factory methods for PortAssignment and PortSecurity enums #455
Closed
sleberknight
started this conversation in
Ideas
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We have configuration classes with
boolean
properties likeuseDynamicPorts
anduseSecurePorts
. When creatingPortAssigner
instances we need to convert these values into thePortAssignment
andPortSecurity
enum values, requiring code like:The ternary expressions are not the prettiest. You could also use an
if/else
but that's not great either. It might be a little nicer to write code such as this:The implementations for the above are simple:
Because I'm not sure I like the above naming (
forDynamicPorts
andforSecurePorts
) here are a few alternative names for thePortAssignment
enum (I asked ChatGPT for some suggestions):fromBoolean
assignDynamicIfTrue
booleanToPortAssignment
getPortAssignmentByFlag
dynamicForTrue
These are somewhat OK, though the ultra-generic ones
fromBoolean
andbooleanToPortAssignment
don't help a reader determine what the return value will be. AndgetPortAssignmentByFlag
makes little sense. But,assignDynamicIfTrue
anddynamicForTrue
aren't bad, and more clearly convey the intent than my original one (forDynamicPorts
). So, perhaps one of those or a variant such asdynamicIfTrue
ordynamicWhenTrue
instead ofdynamicForTrue
.Similarly, for
PortSecurity
,secureForTrue
,secureIfTrue
,secureWhenTrue
, orassignSecureIfTrue
all are more clear thanforSecurePorts
).Beta Was this translation helpful? Give feedback.
All reactions