O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required