Hi JS,
Below is a sample Cairngorm2 FrontController. It's very similar to the .99 version. The store example is using custom events. These are usually created if you need to pass data (VO) with the event to a Command. This isn't necessary if the command doesn't require parameters or data. However, in the store example, the constants are defined in the individual custom event classes. Either method is consistant with best practice. It just depends on the use case and your personal coding preferences. Also, the signature of dispatching Cairngorm events changed between .99 and 2.
package code.control
{
import com.adobe.cairngorm.control.FrontController;
import code.commands.ResizeViewStatesCommand;
import code.commands.ShowAlertCommand;
public class ApplicationController extends FrontController
{
public function ApplicationController()
{
addCommand( ApplicationController.EVENT_RESIZE_VIEW_STATES, ResizeViewStatesCommand );
addCommand( ApplicationController.EVENT_SHOW_ALERT, ShowAlertCommand );
}
//-------------------------------------------------------------------------
public static const EVENT_RESIZE_VIEW_STATES : String = "resizeViewStates";
public static const EVENT_SHOW_ALERT : String = "showAlert";
}
}
-TH
--- In [email protected], "laidezmon" <[EMAIL PROTECTED]> wrote:
>
> Here is a question about Cairngorm best practices.
>
> In the documentation this is in part four feature driven development,
> page 3 for cairngorm .99 it says this:
>
> "First recognize the best practice appraoch of naming all events as
> constants on the FrontController instance ShopController."
>
> Later down it says:
>
> "The compiler catches any mistyped events noisily at compile time
> rather than failing silently at run time. While Cairngorm does not
> require this, its a best practice we highly recommend."
>
> I downloaded the latest Cairngorm store for 2.0 however, and thier
> shopController instance is not written in the same format. I was
> wondering why? In the 2.0 version they do NOT declare constants, but
> in the .99 version they do. What is the best practice?
>
> Below are the two different ShopController code samples. The .99 uses
> static vars, while the 2 version does not. In fact the entire method
> for calling the associated commands from events are different. So
> which is the actual best practice?
>
> Help!
> JS.
>
>
> Here is the .99 ShopController example:
>
> class org.nevis.cairngorm.samples.store.control.ShopController extends
> FrontController
> {
> public function ShopController()
> {
> initialiseCommands();
> }
>
>
> //----------------------------------------------------------------------------
>
> public function initialiseCommands()
> {
> addCommand( ShopController.EVENT_GET_PRODUCTS, new
> GetProductsCommand() );
> addCommand( ShopController.EVENT_ADD_PRODUCT_TO_SHOPPING_CART,
> new AddProductToShoppingCartCommand() );
> addCommand(
> ShopController.EVENT_DELETE_PRODUCT_FROM_SHOPPING_CART, new
> DeleteProductFromShoppingCartCommand() );
> addCommand( ShopController.EVENT_FILTER_PRODUCTS, new
> FilterProductsCommand() );
> addCommand( ShopController.EVENT_SORT_PRODUCTS, new
> SortProductsCommand() );
> addCommand( ShopController.EVENT_VALIDATE_ORDER, new
> ValidateOrderCommand() );
> addCommand( ShopController.EVENT_VALIDATE_CREDIT_CARD, new
> ValidateCreditCardCommand() );
> addCommand( ShopController.EVENT_COMPLETE_PURCHASE, new
> CompletePurchaseCommand() );
> }
>
>
> //-------------------------------------------------------------------------
>
> public static var EVENT_GET_PRODUCTS = "getProducts";
> public static var EVENT_ADD_PRODUCT_TO_SHOPPING_CART =
> "addProductToShoppingCart";
> public static var EVENT_DELETE_PRODUCT_FROM_SHOPPING_CART =
> "deleteProductFromShoppingCart";
> public static var EVENT_FILTER_PRODUCTS = "filterProducts";
> public static var EVENT_SORT_PRODUCTS = "sortProducts";
> public static var EVENT_VALIDATE_ORDER = "validateOrder";
> public static var EVENT_VALIDATE_CREDIT_CARD = "validateCreditCard";
> public static var EVENT_COMPLETE_PURCHASE = "completePurchase";
>
>
> }
>
>
> Here is the version 2.0 ShopController Example:
>
> package com.adobe.cairngorm.samples.store.control
> {
> import com.adobe.cairngorm.control.FrontController;
> import com.adobe.cairngorm.samples.store.command.*
> import com.adobe.cairngorm.samples.store.event.UpdateShoppingCartEvent;
> import com.adobe.cairngorm.samples.store.event.FilterProductsEvent;
> import com.adobe.cairngorm.samples.store.event.GetProductsEvent;;
> import com.adobe.cairngorm.samples.store.event.SortProductsEvent;
> import com.adobe.cairngorm.samples.store.event.ValidateOrderEvent;
> import com.adobe.cairngorm.samples.store.event.ValidateCreditCardEvent;
> import com.adobe.cairngorm.samples.store.event.PurchaseCompleteEvent;
>
> /**
> * @version $Revision: $
> */
> public class ShopController extends FrontController
> {
> public function ShopController()
> {
> initialiseCommands();
> }
>
> public function initialiseCommands() : void
> {
> addCommand( GetProductsEvent.EVENT_GET_PRODUCTS,
> GetProductsCommand );
> addCommand(
> UpdateShoppingCartEvent.EVENT_ADD_PRODUCT_TO_SHOPPING_CART,
> AddProductToShoppingCartCommand );
> addCommand(
> UpdateShoppingCartEvent.EVENT_DELETE_PRODUCT_FROM_SHOPPING_CART,
> DeleteProductFromShoppingCartCommand );
> addCommand( FilterProductsEvent.EVENT_FILTER_PRODUCTS,
> FilterProductsCommand );
> addCommand( SortProductsEvent.EVENT_SORT_PRODUCTS,
> SortProductsCommand );
> addCommand( ValidateOrderEvent.EVENT_VALIDATE_ORDER,
> ValidateOrderCommand );
> addCommand(
> ValidateCreditCardEvent.EVENT_VALIDATE_CREDIT_CARD,
> ValidateCreditCardCommand );
> addCommand( PurchaseCompleteEvent.EVENT_COMPLETE_PURCHASE,
> CompletePurchaseCommand );
> }
> }
>
> }
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
| Software development tool | Software development | Software development services |
| Home design software | Software development company |
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe
__,_._,___

