Timeline for C# convention for empty constructor
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 5, 2024 at 4:54 | history | undeleted | j4j | ||
| Jan 5, 2024 at 4:53 | history | deleted | j4j | via Vote | |
| Mar 25, 2021 at 9:57 | comment | added | Flater | [..] In other words, if there was a use for a parameterless constructor, your code would contain that parameterless constructor. By not having it, you are stating very clearly that this class should only be instantiated using the parametered constructors that the class does contain. In such a case, the third party consumer's code did not wrongly break. It broke the way you specifically wanted it to, by no longer allowing the use of the parameterless constructor. | |
| Mar 25, 2021 at 9:53 | comment | added | Flater | It makes no sense to blanket add parameterless constructors without observing the specific context. If the new version of the software now intentionally forces there to be parameters in the class constructor, and does not provide a parameterless constructor, then it's correct that third party code can no longer use a parameterless constructor anymore. This is why versioned releases matter. If customers don't want their parameter-constructor-using code to break, they simply should not be upgrading to this newer version which no longer allows the parameterless constructor. | |
| Mar 25, 2021 at 7:48 | comment | added | nvoigt | "If you don't add an empty constructor explicitly, the third party code will be break." So will your unit tests and that is when you know you need to add the empty constructor. Don't add empty constructors just because you may not remember someone uses them. Your tests do. You do have unit tests right? | |
| Mar 25, 2021 at 5:16 | comment | added | Doc Brown | This answer, though it contains some wisdom, does not match the question, which was not about constructors with no arguments, but about constructors with an empty function body. | |
| Mar 25, 2021 at 1:58 | history | answered | j4j | CC BY-SA 4.0 |