问题
Technology stack: One REST API developed in .Net Core 3.1. Two client apps one in Android and other in iOS
Scenario: Store enum value in the database such that when the data is uploaded to the API it makes sense (API can take decisions based on the enum).
Option 1: Store enum as a number and copy it in the API.
In this scenario, the enum value would be saved in the DB and transferred to the API. When the API need to use the enum for a condition or some other use, it would use the copy of the enum present in the API.
Pros: No extra handling.
Cons: Have to maintain enum in API. If a new value is added in the enum on the client side then the API would have to be changed and published again (The whole SDLC lifecycle).
Option 2: Store enum as a number and add a table for each enum in the API.
In this scenario, the enum value would be saved in the DB and transferred to the API. When the API need to use the enum for a condition or some other use, it would get the info of the enum from its table present in the API.
Pros: No need to change API code when a new value is added in the enum.
Cons: Extra DB call to get enum value. Many small tables for each enum.
Option 3: Store enum as a number and add an enum table for all the enums in the API.
In this scenario, all the enums value would be saved in the single table of the DB and transferred to the API. When the API need to use the enum for a condition or some other use, it would get the info of the enum from the enums table present in the API.
Pros: No need to change API code when a new value is added in the enum. No need to add new tables when a new enum is introduced.
Cons: Extra DB call to get enum value. String comparison.
Option 4: Store enum as a string and transfer string value to the API.
In this scenario, the enum would be saved as a string. When the API need to use the enum for a condition, it would simply use string comparison.
Pros: No need to change API code when a new value is added in the enum. No need to make extra DB call for enums.
Cons: String comparison?
来源:https://stackoverflow.com/questions/61931829/decide-enum-storage-which-is-uploaded-to-the-server-and-shared-by-a-client-app-a