API / Apache Velocity Interview questions
Why should you avoid putting business logic inside Velocity templates?
Even though VTL technically allows some computation via #set and method calls on context objects, piling real logic, validation rules, discount calculations, permission checks, into a template causes the same problems JSP scriptlets caused: the logic becomes hard to unit test, hard to reuse outside that one template, and invisible to normal Java tooling like debuggers and static analysis.
It also creates a maintenance trap where two people, a Java developer and a template author, can both silently change the same business rule in different places without either one noticing.
The recommended pattern is to push any real decision-making into a plain Java object (often called a "tool" or view-model), expose only its already-computed result to the context, and let the template do nothing more than lay that result out.
More Related questions...