23.2. ViewHelper and ViewLocator

The problem of notifying views without having to bind to properties on the ModelLocator was one the creators of Cairngorm took into account.

In the com.adobe.cairngorm.view package you will find two classes: the ViewHelper and the ViewLocator (both are currently deprecated). The documentation for the ViewHelper class describes it in this way: "Used to isolate command classes from the implementation details of a view."

Cairngorm best practices specify that command classes should interact with the view using the model, but in some instances command classes may need to both interrogate and update the view directly. Before performing any business logic, the command class may need to fetch values that have been set on the view. Following completion of any business logic, the final task may be for a command class to update the view (user interface) with any results returned, or perhaps to switch the view entirely (to a different screen).

By encapsulating all the logic necessary for interrogating and updating a particular view into a single helper class, we remove the need for the command classes to have any knowledge about the implementation of the view. The ViewHelper class decouples our presentation from the control of the application.

A ViewHelper belongs to a particular view in the application; when a ViewHelper is created, its id is used to register a particular view component (such as a particular tab in a TabNavigator, or a particular screen in ...

Get Professional Cairngorm™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.