7.1. What Are They?

Commands are the classes that determine how the event that triggers them should be handled. According to the article "Flex 3: Introducing Cairngorm" (Adobe Customer Training/Partner Enablement Group, Burleson, Shuman, and Boles), the commands have the following characteristics:

  • Each command class represents a specific business feature with associated business logic and processing.

  • Commands update the ModelLocator with new data or changes to existing data.

  • All commands have the same entry point to initiate or start business processing: execute().

  • Command implementations have class names that are equivalent to business events (e.g., LoadPhotosEvent and LoadPhotosCommand).

Commands classes decide how Cairngorm events are handled. When a Cairngorm event is dispatched, the FrontController calls the execute function on the command class that is registered for the event.

The execute function contains the logic that needs to be executed. This may include accessing remote services using a delegate class or it may simply update the ModelLocator. Regardless of whether services are used or the ModelLocator is simply being updated, command classes are the only classes that should be updating data on the ModelLocator.

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.