Does StringTemplate break separation?

I noticed the following in the introduction for StringTemplate:

StringTemplate interprets op looking for property p inside object o. Search rules differ slightly between language ports, but in general they follow the old name JavaBeans conventions. StringTemplate looks for getP (), isP (), hasP () methods. If he cannot find one of these methods, he searches for a field called p.

This is not like this article: http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf

Doesn't this open the door to breaking the model / view separation, essentially allowing the model to retrieve data by invoking a method? A bad programmer could write a getP () method that causes side effects. How does ST "strictly" provide separation of concerns here?

+4
source share
1 answer

Every single template language out there does just that: Velocity, FreeMarker, StringTemplate and JSP / JSF Expression Language.

Separation of problems is what the programmer should care about, not opinion. People are expected to write the side effects of get / is / has so that everyone can name them without worrying about it. This is why these methods must be accessories, and there are methods commonly called setSomething that must be mutators.

If someone writes their own classes and decides to define a getSomething method that has a side effect, they run counter to the general belief, and the tools do not have to accept all the assumptions when working with objects, they just hope that people will be smart and respect healthy meaning and write code, as everyone else writes.

+6
source

All Articles