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

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.