Recently I have to write an API interface that dynamically displays the page, thinking about separating the content from the display-way in order to reuse the dispaly configuration. The general design is like this:
-
Display the template table template;
-
Display the content table element, which is divided into several different types, corresponding to different data and display types;
-
Multiple content tables, detail_xxx, specific content, such as which products, have nothing to do with the display;
-
Corresponding to the content table, multiple display tables, display_xxx, determine the data display format, such as margins, image size, and so on.
There is a certainty in the details, how is the association between element, detail and display better?
Option 1: Associated in the detail table, put the display_xxx_id in the table detail_xxx. It was also the original idea, but according to the MVC design, this method did not completely separate the content and display, and detail may be a list, in most cases;
Option 2: The id association of the element table, the elementid is added to the detail_xxx, and added to the display, so that the coupling degree is low, but the multiplexing degree of the display is not high, and the data is easy to be redundant;
Option 3: The element table is associated with the field, detail_id, and display_id. In this way, the display is reusable, and the content and display are weakly related.
Now, I use the compromise between option-2 and option-3, element-detail, adds elementid association in the detail table, because the detail is a list in most cases; element-display adds displayid association in element table because display is unique.
I want to know which is better, and how to design the association between content and its display?
Aucun commentaire:
Enregistrer un commentaire