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.3. How Do You Create It?

Since implementing the IModelLocator is optional, it is up to you if you wish to select that interface during the class creation process in Flex Builder. Whether you implement the IModelLocator interface or not, you will still need to implement the singleton pattern.

In a typical Cairngorm project, the ModelLocator is created in the model package, as is done in the FStop application seen in (Figure 4-1).

Figure 4.1. Figure 4-1

It is also acceptable to have multiple model classes as seen in the Cairngorm Store application (Figure 4-2).

Figure 4.2. Figure 4-2

The general naming convention for ModelLocator classes is to prefix the word model or locator with something describing what the model represents, as in (Figure 4-2). Some developers use the application name as prefix when there is only one ModelLocator class for the entire application.

To create a ModelLocator simply give it a name as seen in (Figure 4-3) and click the Finish button.

Figure 4.3. Figure 4-3

Once you have the basic class created, you add the private static instance variable and getInstance function, as in the following:

package com.cairngormexample.model { public class CairngormExampleModel ...

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