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

9.4. How Do You Use Them?

Value objects are used to pass data between layers of the application. Most often this transfer takes the form of passing an instance of a value object being passed between event, command, and if necessary, delegate classes. This can be seen in the UpdateShoppingCartEvent and AddProductToShoppingCartCommand classes from the Cairngorm store.

The UpdateShoppingCartEvent has a public property product that holds an instance of a ProductVO:

package com.adobe.cairngorm.samples.store.event
{
  import com.adobe.cairngorm.control.CairngormEvent;
  import com.adobe.cairngorm.samples.store.vo.ProductVO;
  import flash.events.Event;
  public class UpdateShoppingCartEvent extends CairngormEvent
  {
    public static const EVENT_ADD_PRODUCT_TO_SHOPPING_CART : String =
"addProductToShoppingCart";
    public static const EVENT_DELETE_PRODUCT_FROM_SHOPPING_CART : String =
"deleteProductFromShoppingCart";
    public var product : ProductVO;
    public var quantity : Number;
    public function UpdateShoppingCartEvent( type : String,
    bubbles : Boolean = true, cancelable : Boolean = false )
    {
      super( type, bubbles, cancelable );
    }
    override public function clone() : Event
    {
      return new UpdateShoppingCartEvent( type, bubbles, cancelable );
    }
  }
}

This product property is then referenced in the AddProductToShoppingCartCommand via the event, as can be seen in the following:

package com.adobe.cairngorm.samples.store.command { import com.adobe.cairngorm.commands.ICommand; import com.adobe.cairngorm.control.CairngormEvent; ...

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