4.5. Summary

In this chapter you examined the ModelLocator class and the associated IModelLocator interface. 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 IModelLocator interface does not define any functions, but rather serves as a data type marker. Some developers do not bother implementing the interface.

Creating a ModelLocator class is generally the same as creating any other class in Flex, except that you are responsible for implementing the singleton design pattern. The ModelLocator class(es) are created in the model package, and many developers use the naming convention of prefixing the word model or locator with the name of the application.

Once the ModelLocator class has been created, you simply add public properties to it representing the data that needs to be shared. In many cases the properties on the ModelLocator store instances of one of the mx.collections classes or instances of value object classes, but they can be of any type of data.

Views subscribe to be notified of changes in the ModelLocator class using data binding. Views obtain references to the properties on the ModelLocator by retrieving the single instance of the ModelLocator using the static getInstance method and then referencing the public properties on 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.