Transform view pattern

From CSSEMediaWiki
Revision as of 10:52, 19 October 2010 by Martin Doms (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
A transformer object is passed a reference to a serializable model object. This is transformed into a form which can be rendered, and is written to the response stream.
Transform View is typically an alternative to Template View. It takes objects from the model and transforms them to a format that can be rendered, such as HTML. The most common way of doing this is to transform XML-serialized domain objects using XSLT. This pattern is commonly coupled with another web presentation pattern such as Front Controller or Page Controller which parses the incoming request and supplies the domain objects to be transformed.

Fowler argues that this method can be cumbersome for developers because XSLT is a functional language which may be difficult for regular imperative-minded programmers to understand and apply. In this writer's opinion this criticism is becoming less valid every day. Typical programmers are exposed to more and more functional and declarative languages and language features such as LINQ, SQL and the lambda expressions available in a wide variety of modern programming languages.

Another criticism of this pattern is the lack of availability of quality XSLT tools when compared with editors that are compatible with XHTML and therefore play well with Template View.

The main advantage of this pattern is the ability to generate views from platform-agnostic XML. This means the input to the transformer can come from any language or platform as long as it is valid XML. This also leads to more testable code as the transformer output is not dependent on a web server or framework.

Personal tools