I've been trying to build this (principally desktop, but could eventually be turned into a cloud app) document editor program for a while and have it laid out using the broad principles of the 3-Layer (Data, Model, and UI) and MVC (Model-View-Controller) patterns, and one thing I've often run into is where to best put little odds-and-ends bits of logic that seem to inherently cross more than one layer.
For example, in any classic desktop document editor, when you create a new document, it typically ends up with a "name" shown on its window or tab, often something like "Untitled" or "Untitled Document" - most especially though, followed by a counter, such as "Untitled Document 3" (counting off how many new documents you've created). This obviously requires one of those text strings to be in the program, somewhere, and presented to the user. This label, of course, gets replaced when you "Save" the document to a file.
Right now, the way I have it is that these names are generated in the Model layer, i.e. the logic that creates a new document hard codes the string "Untitled Document" or similar in the business logic layer and then appends the counter. Trouble is:
- this "feels" like an inherently UI-related concern,
- but because the string involves a counter that is part of the document creation logic, we must generate that string dynamically in connection therewith, and thus feels most like we need to push it down to the Model layer, but then
- internationalization - what if we want to supply a translation to a foreign language? Given the model layer is agnostic to the UI layer, and the UI layer may (does!) use a widget system with its own feature to supply the translated strings for things wholly in that layer, we could easily end up with at least 2 different methodologies of translation at the same time, which "feels wrong" or "like a mess".
How should this be handled? Where should this kind of seemingly cross-cutting logic go?