TL;DR: Say you have, in a website application, a permission system (user can/cannot access specific section). You need a "name" for this permission/right (eg. can_access_admin) which will somehow be used by storage system (to keep track the fact a user has this right) and into source code (to ask fetch into storage to see if user has the right to access admin area). What form this right "name" has? bits? string? How to use it efficiently in source code: as it (copy/paste)? constant?
When designing a website application you oftenly use concepts such as user permission (eg. access to admin area is granted) and preference (eg. maximum number of results to display in projects list) that will be used among all application.
It boils down to a reference/ID in the form of a string (eg.
can_access_admin), bit sequence (eg.
10111) or even integer (
42) to use in your source code:
- Where you fetch value/presence from storage
- Where you check/compare
- Where you display UI forms to change values
Note that the same concept will surely be used in storage (in the same form or in another):
- Database: user-rights map table.
- Configuration file: default values of preferences.
The issue I have is: how to avoid copy/pasting that "reference" over all the source code (which will be a real pain if you ever need to change that in the future)? It can be abstracted into language's constant or even class but it will create more versions of the same concept and this cannot always be used into storage.
4.preferences_view.html, the actual "XXXXXX" value is either fetched from Storage (when user already has defined preference): 150
or from configuration file (when user has no preference set): 100
The controller populating that view have to deal with:
- HTML input name:
- DB Storage code name:
- Configuration Storage node path: