Skip to Main Content
Professional Cairngorm™
book

Professional Cairngorm™

by Jeremy Wischusen
November 2009
Intermediate to advanced content levelIntermediate to advanced
357 pages
8h 20m
English
Wrox
Content preview from Professional Cairngorm™

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional Java® JDK®, 6th Edition

Professional Java® JDK®, 6th Edition

W. Clay Richardson, Jeff Scanlon, Donald Avondolio, Mark W. Mitchell, Scot Schrager

Publisher Resources

ISBN: 9780470497265Purchase book