4.2. What Does It Look Like?

The interfaces associated with the ModelLocator are found in the com.adobe.cairngorm.model package. The following interfaces are found in this package:

  • IModelLocator: Marker interface used to mark the custom ModelLocator.

  • ModelLocator: Deprecated as of Cairngorm 2.1 and replaced by com.adobe.cairngorm.model.IModelLocator.

The code for the IModelLocator interface is as follows:

package com.adobe.cairngorm.model
{
  public interface IModelLocator
   {
   }
}

No methods are actually defined in the interface. The only purpose of this interface is to allow data typing to mark a class as an instance of a ModelLocator.

Many developers do not even bother implementing the interface in their ModelLocator classes. Such an implementation might look like the following:

package model
{
  import mx.collections.ArrayCollection;
  import com.someproject.vo.UserVo;
  [Bindable]
  public class ModelLocator
  {
    static private var __instance:ModelLocator;
    public var user:UserVO;
    public var items:ArrayCollection=new ArrayCollection();
    public var purchasedItems:ArrayCollection=new ArrayCollection();
    public function ModelLocator()
    {
      if ( modelLocator != null )
     {
        throw new Error( "Only one ModelLocator instance should be instantiated");
     }
    }
    static public function getInstance():ModelLocator
    {
if(__instance == null)
      {
        __instance=new ModelLocator();
      }
      return __instance;
    }
  }
}

In the preceding example you can again see the implementation of the singleton pattern with the private static instance ...

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.