4.1. What Is It?

The ModelLocator is one of the core singleton classes of the Cairngorm framework. The ModelLocator serves as a central repository for storing data that needs to be accessed in multiple locations. According to the article cited in earlier chapters, "Flex 3: Introducing Cairngorm" (Adobe Customer Training/Partner Enablement Group, Burleson, Shuman, and Boles), the ModelLocator has the following characteristics:

  • It is a global singleton repository for shared or global data.

  • It does not load or persist data to a permanent data store.

  • It does not contain business logic.

  • It supports data binding for auto-notifications of data changes to views.

The ModelLocator class acts as a centralized location for accessing shared data. This data is shared via public properties on the ModelLocator class. Classes that need to access this data retrieve the single instance of the ModelLocator using the static getInstance method and then refer to the public properties.

The ModelLocator differs from other possible implementations of the MVC pattern in that it does not contain any application logic. In some implementations of the MVC pattern the model contains functions for registering the listeners and then notifying them of changes in the data (observer pattern). Cairngorm performs these actions through the Flex data-binding mechanism, and that is how you should have views subscribe to changes in the state of the properties held in the ModelLocator.

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.