Enum vs config file

we want to implement business logic based on records in the table. We have two options.

One way is to create an enumeration in code for each record in the table, and in the code, compare the enumeration with the read record to decide which logic comes next. The disadvantage of this system is that if the key changes in the table (for example, in the autorun fields), the application needs to be recompiled to reflect the changes.

The second way to do this is to store the variables in a config file for each record in the table, and in the code compare the config variable with the read record to decide which logic comes next. The interaction with this system is that the configuration file can be processed and the application will stop working.

What is the best programming pattern for this question?

0


a source to share


4 answers


Why not keep everything together and put the table in a database that tells you which business record table is next?



Sorry I cannot give a better answer. I need more information on what your business logic is trying to do and what orders these entries might be.

+2


a source


I approve of your first approach. If the logic changes enough to require a change in your autonumber field (either by deleting the old entry or adding a new one), you will still have to change your code to reflect the new paradigm.



+1


a source


Enumerations must be static and immutable. If you have a solution that requires a change to enumerate, then enums are the wrong solution.

Front-end configuration really suffers from the problems you mentioned, so it is not always a good choice. To help with this, you can encrypt it so that it is not easily modified.

Another alternative would be to create a DLL resource that has a config file as a resource, so it cannot be easily modified. When you need to make changes, you only need to compile the DLLs and deploy only that, not the whole application.

Scott Langham mentioned using a config table in your database. This is also a good idea. Is this possible with your setup?

0


a source


This sounds like something like a state template. I assume you have a table that stores the states (ID, name) and logic associated with each in your application. Given the state id, given the logic you have to follow. You need to decide how to create the correct state, if you are using an ORM you can use a discriminator (state id in this case).

0


a source







All Articles