<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>I previously went through setting up a RubyAMF gateway to provide AMF responses, and the next step was to build a Rich Client to consume this service. A simple tag cloud on its own does not demand the overhead of a framework, but explaining how to use a framework sensibly is often suited to simple examples, so that's how we'll start.

If you haven't used PureMVC before, I'd recommend visiting "http://www.puremvc.org":http://www.puremvc.org and reading through the excellent "Best Practices":http://puremvc.org/component/option,com_wrapper/Itemid,174/ [pdf] documentation. The following notes should reflect some of these best practices along with some we've settled on at LBi.

Our app, like all PureMVC apps, will begin with the @ApplicationFacade@. Based on the "Facade":http://en.wikipedia.org/wiki/Facade_pattern design pattern, the name already gives an indication of its purpose. In the case of PureMVC, the @ApplicationFacade@ provides a single interface to work with the core Model, View, and Controller actors without a developer having to worry about dealing with them directly. Once we instantiate the @ApplicationFacade@ in the main class we call its startup method which sends a Notify.STARTUP notification to kick the app into life:
&lt;code lang="actionscript"&gt;
public function startup( app:* ):void
{
	sendNotification( Notify.STARTUP, app );
}
&lt;/code&gt;

The Notification system within PureMVC is based on the "Observer":http://en.wikipedia.org/wiki/Observer_pattern design pattern, and is a straightforward approach to enabling commmunication between the various actors within the framework. We prefer to define @Notification@ constants in a separate Notify class instead of directly within the @ApplicationFacade@, and in a more complex application you might want to think about logically breaking notifications into separate classes, and in the case of Models, defining them on the associated Proxies which send the Notifications (more on this later).

The Notify.STARTUP Notification triggers activity because in the same @ApplicationFacade@ class we've mapped this particular notification to a specific Command:

&lt;code lang="actionscript"&gt;
override protected function initializeController():void
{
	super.initializeController();
	registerCommand( Notify.STARTUP, StartupCommand );
&lt;/code&gt;

The "Command":http://en.wikipedia.org/wiki/Command_pattern design pattern involves creating stateless objects which execute actions in response to specific events. PureMVC provides both simple commands, which have an @execute@ method, and macro commands, which list a number of simple commands which should be executed in order. Because a number of commands may be required at application startup,  StartupCommand is defined as a macro command:
&lt;code lang="actionscript"&gt;
public class StartupCommand extends MacroCommand
{
	override protected function initializeMacroCommand():void
	{
		addSubCommand( ModelPrepCommand );
		addSubCommand( ViewPrepCommand );
	}
}
&lt;/code&gt;

I'll detail how these commands are used in the next post.</body>
  <created-at type="datetime">2008-12-09T20:47:09Z</created-at>
  <ham-comments-count type="integer">0</ham-comments-count>
  <id type="integer">27</id>
  <permalink>basic-architecture-of-a-puremvc-application-part-i</permalink>
  <title>Basic Architecture of a PureMVC Application: Part I</title>
  <updated-at type="datetime">2008-12-09T21:38:43Z</updated-at>
</post>
