Decide enum storage which is uploaded to the server and shared by a Client app and an API

孤人 提交于 2020-05-30 08:42:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!