note
mvc
<p>
Here we have a classic conflict of design forces:
</p>
<ul>
<li>Encapsulation
<li>Seperation of concerns (cohesion)
</ul>
<p>
If you put the UI code in the object, you are encapsulated but your object is now doing its regular work + UI work (low cohesion). If you keep it as is, you get clean seperation of concerns, but break encapsulation.
</p>
<p>
There are other solutions that could balance these forces better. The balance of forces you want depends on your requirements.
</p>
<p>
You could, for example, have the template code look like this:
</p>
<pre>
<% item.getReceivedUI("<input ...>") %>
</pre>
<p>
The item object <code>getReceivedUI()</code> will check if receive is possible, if so interpolate the parameter as a TT template with <code>item.received</code> in the stash. If not, it returns <code>item.received</code>. Then you remove the UI code from the item object by delegating the actual interpolation to some strategy object, that may use TT or anything. Thus the item knows not about UI, just about presentation logic. The template is still in charge of the UI. Is this extra work worth it? Depends on your requirements.
</p>
259306
259939