|
16 | 16 | - Abstract methods in enums {abstract} |
17 | 17 | - Conclusion {conclusion} |
18 | 18 | description: "Working with enums." |
19 | | -last_update: 2023-09-28 |
| 19 | +last_update: 2023-09-29 |
20 | 20 | author: ["DanielSchmid"] |
21 | 21 | --- |
22 | 22 | <a id="intro"> </a> |
@@ -189,13 +189,18 @@ enum MyEnum { |
189 | 189 | <a id="conclusion"> </a> |
190 | 190 | ## Conclusion |
191 | 191 |
|
192 | | -All in all, enums provide a simple and safe way of limiting the instances of a type |
193 | | -while preserving most of the flexibilities of classes. |
| 192 | +All in all, enums provide a simple and safe way of representing a fixed set of constants |
| 193 | +while keeping most of the flexibilities of classes. |
194 | 194 |
|
195 | 195 | However, care should be taken when using enums where the number (or names) of instances is subject to change. |
196 | | -Whenever enum constants are changed, there may be compilation errors, runtime errors or other inconsistencies |
197 | | -due to other code expecting the original version of the enum. |
| 196 | +Whenever enum constants are changed, other code expecting the old version of the enum might not work as expected. |
| 197 | +This may manifest in compilation errors (e.g. when referencing a removed enum constant), |
| 198 | +runtime errors (e.g. if there is a `default` case even though the new enum constant should be handled separately) |
| 199 | +or other inconsistencies (e.g. if the value of the enum was saved to a file which is then read and expecting that value to still exist). |
| 200 | +When changing enum constants, it is recommended to review all code using the enum. |
198 | 201 | This is especially important in cases where the enum is also used by other people's code. |
199 | 202 |
|
200 | 203 | Furthermore, it might be worth considering to use other options |
201 | | -in case of many instances since listing many instances at a single location in code can be inflexible. |
| 204 | +in case of many instances since listing a lot of instances at a single location in code can be inflexible. |
| 205 | +For example, it may be better to use a configuration file for listing all instances |
| 206 | +and reading these configuration files in the program in cases like this. |
0 commit comments