There is nothing wrong with storing any data in a database, including presentation data. If this helps you get effective results while writing less code, then this is good practice. You need to make sure that you are not confusing your presentation logic with the database logic.
You can make sure that these problems are separated by encapsulating the data for your presentation level in the properties of the elementInfo object (for example).
Since this is the CSS class you are talking about, this presentation data should be stored separately from business data. . Thus, while it is normal to store both presentation data and business data in the database, it is unacceptable to store them in one table.
Refresh re: comment No, you should not add the PresentationClassRecord identifier as the FK for the business object. I made a sample db approach below. I called DummyTable your business objects, and the rest are specifications. The most important part is StatusPresentationAssignmentTable
----------------------------------------------- DummyTable ----------------------------------------------- Id Name SomeOtherDataField StatusId PK int varchar int FK int ----------------------------------------------- StatusTable ----------------------------------------------- Id Name ModifiedDate PK int varchar datetime ----------------------------------------------- PresentationTable ----------------------------------------------- Id PresentationType Value PK int varchar sample data: 43 CssClass prettyBackground ----------------------------------------------- StatusPresentationAssignmentTable ----------------------------------------------- StatusId PresentationId FK int FK int
Now with two simple connection conditions, you can get presentation data and completely separate it from your business data. Your script might do something like checking if the Dummy status has any presentation purpose. If so, he looks at PresentationType, gets the appropriate function for applying presentation data to the presentation, and executes it. (You will need to have a function for each PresentationType that knows how to handle the value - something that can be encapsulated with something like function applyPresentationValue(presentationElement, presentationType, presentationValue) , which calls another function applyCssClass(presentationElement, value) if presentationType == "CssClass" ).
smartcaveman
source share