 |
 |
|
|
|
Why not use Commands as Async Responders? |
|
|
|
Wednesday, 09 July 2008 |
QUESTION: As the Command is instantiated and executed locally in a controller function, theoretically the Command object is immediately available for garbage collection when the method finished executing, right? Now what if you setup asynchronous event listeners in the Command's execute function? Everything was fine in my case and events were fired and executed correctly but I nevertheless felt a bit unsure about it... quite a few things have changed in AS3 with GC and one can easily run into a situation where listeners aren't executed because the source already has been collected.
ANSWER: - Within a PureMVC application, there are a couple of reasons:
1. Commands should be stateless. They are the object-oriented equivalent of a subroutine - a little place for us to break down to some procedural code, which is by definition synchronous in nature. By making a running Command a responder to an async process like a service call, you have given it state. It is in a waiting state. If it has a long timeout and the user clicks a 'stop' button, how do you interrupt it? You can't. You can have another Command tell the delegate to cancel the HTTPService call, but does that free the reference to this Command, which was on the responder list for the call?
You have handed a reference to a Command to another framework that you don't control. You have no way to ensure that that reference will eventually resolve to a result or fault callback (and that the framework has cleaned up its reference before returning) that will collapse scope and make the Command go away. Also, remember this pattern is implemented on multiple platforms, so any assumptions about the how the reference will be resolved by other framework (Flex, J2ME, etc) may not hold universally, so the practice must be one that can be advocated on any platform..
Meanwhile a Proxy is a registered, long-living actor and the framework has a method for removing it or retrieving it (for instance to tell it to cancel an operation). The framework can only remove a mapping for a Command. This is why we only have the Controller create and execute Commands and we avoid giving them state so they get their work done and go away, and we control their scope.
2. This is Domain Logic not Business Logic. There is a distinction between the two. Business logic is concerned with coordinating valid interactions between View and Model. Domain Logic is about keeping an internally consistent Model representation on both sides of the app (client and server).
The Proxy's job is to hide the location of the data, and make it irrelevant to the rest of the application. The View and Controller regions need only know that a particular Proxy wants to be communicated with in a synchronous fashion or async.
This is why services have been entirely relegated to the Model region. You can write a more portable Model this way.
Several applications with different use cases and View/Controller arrangements may employ the same Model classes without having to reimplement or copy the code for keeping the Model internally consistent.
-=Cliff> |
|
|
PureMVC on the Web
The guys over at Pyjamas (a Python port of GWT) have made their compiler so efficient that it can take virtually any Python library and it will compile to Javascript. They loved the look of PureMVC Python, and decided to do a couple of demos that use it. • Pyjamas Project • EmployeeAdmin Demo: Original / Pyjamas • Pyjamas PureMVC Timesheet Demo |
|
Chandima Cumaranatunge, co-author of the O'Rielly book AS3 Design Patterns, and long-time PureMVC community member recently created a simple Flash/AS3 MultiCore demonstration application accompanied by an informative article that's an excellent introduction to the benefits of working with MultiCore. • Who Moved the Cheese? - Demo / Source / Article
• ActionScript 3 Design Patterns |
|
FlashDevelop has gained quite a bit of ground in the development community so naturally several folks have created templates to ease the burdon of creating implementation classes. We'll let you be the judge of which are the best. • FDT PureMVC Templates, Well Formed and Pimped - Aron Woost • PureMVC First Thoughts and FlashDevelop Templates - Dave Keen
• FDT Templates for PureMVC/AS3 Available - Pedr Browne |
|
Prudential wanted an intimate but exciting way of communicating with customers, so Downstream created a coffee table with a twist—the Interactive Coffee Table. Visitors can navigate floor plans, see and edit their agenda for the visit, and browse images and info about Prudentials history in a technologically advanced multiuser environment. Downstream's programmers used ActionScript 3 on the Adobe Air runtime, the PureMVC framework to keep the code well structured, and Papervision3D for various 3D effects in the application. • Prudential Interactive Coffee Table • Downstream Design
|
|
Ahmed Nuaman has published a well conceived and received AS3/PureMVC tutorial at FlashTuts.com. It's a good place for the learner to get their feet wet, and goes into the difference between using PureMVC with Flex as opposed to Flash or pure AS3. • Understanding the PureMVC Open Source Framework • FlashTuts Website • Ahmed's Website
|
|
Recent Project Activity
Version 2.0 of the PureMVC JavaScript port is now available. It is a complete rewrite based on Mootools core for class simulation.
• Visit the PureMVC JS Port |
|
The PureMVC AS3 / Flex EmployeeAdmin Demo has been refactored to use the standard demo look and feel, and to reflect the very latest best practices. If you are the author of a port of this demo, please read the version.txt file. • Run the EmployeeAdmin Demo • Visit the Project • View the source. |
|
The PureMVC Java MulitCore GWT EmployeeAdmin Demo has been updated, now using Google Web Toolkit 2.0.
• View the Demo • GWT EmployeeAdmin Project |
|
The AS3 Undo Utility adds the ability to undo/redo actions in your PureMVC based Flex, Flash or AIR applications. The latest version is ready for download, and be sure to check out the demo to see how to implement. • AS3 Undo Utility • Flex HistoryPanel Demo |
|
The 3.0 release of PureMVC C# Standard now ships with complete API docs and supports .NET 3.5 & Silverlight 2.0 UPDATE: Get your mobile on! VS2008 Solutions added for PocketPC, Smartphone, and Windows CE! • PureMVC Standard for C# • PureMVC Silverlight Login Demo |
|
|