Note that there are some explanatory texts on larger screens.

plurals
  1. POShould models or views generate strings for humans?
    text
    copied!<p>Here is an issue I've confronted in multiple user-facing applications: a program contains components for graphical rendering of data, (call them <em>views</em>) and other components for managing those data (call them <em>models</em>). Some of those data are in the form human friendly text, often key value pairs such as </p> <pre><code>System Load: 20% Running Time: 20mins 30sec </code></pre> <p>But which software component should be responsible for constructing the text strings? You could argue</p> <ul> <li><p><strong>The model:</strong> should choose the text while leaving the view to display it. This way the views don't have to know exactly which data are provided, and (probably) lets the model expose only a small API. Also it means that the text stays consistent across multiple views (or UI toolkits). This ways views don't have to worry about i18n.</p></li> <li><p><strong>The view:</strong> should do it because this is a UI issue, not part of the business logic. After all, the choice of text is not always cleanly separable from rendering. This way models don't have to worry about i18n.</p></li> </ul> <p>How should I settle, or think about this division of labour? Any ideas?</p> <p><em><strong>Note 1</strong></em>: I don't think this issue is restricted to MVC designs, although that's where I get my terminology.</p> <p><em><strong>Note 2</strong></em>: While researching this question I stumbled across <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter" rel="nofollow noreferrer">Presenters</a>, and <a href="https://stackoverflow.com/questions/5717641/models-views-view-models-and-presenters">ViewModels</a>. Are they supposed to do this kind of work, and when is such a proper/complicated solution worthwhile, and when is it OK to just do it in the Model or View.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload