Say, I have a table Categories. On a page I have a header and for each category the colour of a header varies. A colour is of the presentation level and I've heard that what's related to the UI/presentation level shouldn't be stored in a database.

There must be exceptions. However, in this case I figure that a colour indeed shouldn't stored in a database.

Then there - in a config or in code? How will that make a difference, why will that be better?

In general, what do you make of this rule?

  • It depends on the UI framework you're using. Some frameworks already provide a solution for this, for example, XAML-based frameworks such as WPF and Xamarin already have the tools in place to allow you to add styles and themes to your app. – Ben Cottrell Dec 23 '17 at 14:53
  • How is it determine which color to use for category A and which color for category B? – Bart van Ingen Schenau Dec 23 '17 at 15:04
  • @BenCottrell, yes, so what? what if I'm not using a framework? – Kakki Dec 23 '17 at 15:51
  • @BartvanIngenSchenau by storing that information somewhere. where - what's my question about – Kakki Dec 23 '17 at 15:52
  • 3
    This would be a better question if you could tell us what actual problem you're trying to solve. – Robert Harvey Dec 23 '17 at 16:38

Presentation data (or metadata) should not be stored with the data. It has nothing to do with the data.

You say "page with a header", so I'm assuming HTML. This sort of information is usually handled with CSS. If you have an external CSS stylesheet, then you can change the color associated with a given category just by swapping out the stylesheet.

For Presentation in general, this is the general idea behind theming. If you store presentation metadata in an external file that the UI layer reads at startup to determine the display characteristics, then to change the display, you simply change to a different external file. No need to rebuild the application.

This adds some complexity to the presentation layer when building the application, with the benefit of flexibility in display afterwards. The tradeoffs are up to you to resolve.

| improve this answer | |
  • you didn't understand my question. CSS -- how will it help? do you suggest to hard-code "category_id" -> "colour" in CSS or what? what if I add 5 categories today and tomorrow remove 8? – Kakki Dec 23 '17 at 15:50
  • 3
    Listen, it looks like you're set on storing this information in the database anyway, and trying to get someone to tell you it's OK. If that's the case, then go ahead, it's OK. – Mark Benningfield Dec 23 '17 at 16:01
  • it just looks like. – Kakki Dec 23 '17 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.