Answer the question
In order to leave comments, you need to log in
boolean property or function
We had a dispute at work about adding a boolean property in C#.
Suppose we have a class responsible for storing authorization parameters. Authorization can be by login or by certificate.
The dispute is whether to add a property to determine the type of authorization, or to focus in the code on the completion of the certificate field.
The class is further serialized to xml.
Answer the question
In order to leave comments, you need to log in
From the point of view of code evolution, it is safer to use, for example, enumerations (enum). Not “more correct”, but “safer”, in the sense of future modifications.
Suddenly (for sure?) You will need additional authentication methods (OAuth for example)? In the case of using enums (or other analogues of the "visitor" pattern - such as case classes from Scala), the development environment will tell you where you forgot to take into account the new authentication option. I don't know about Visual Studio, but Eclipse or IDEA will give a warning in the following code:
switch (principal.getAuthMethod()) {
case LOGIN: /* Login / password auth */
break;
case CERTIFICATE: /* Certificate auth */
break;
}
The fullness of the certificate field indicates only the certificate, it cannot speak about the type of authorization. It can only indirectly hint, and this hint, by coincidence, can be true - but you can’t rely on it 100%, especially considering the possible evolution of the code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question