view the presentation deck (powerpoint)
TRANSCRIPT
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
Page 1
AFFUG PresentationExploring the Flex Data Services Framework:
From Prototypes to Large-Scale Applications
October 15th 2008
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
What we’ll cover today
• Overview of Flex Data Classes
• Deep dive into some of the key classes you need to know
• Discuss concepts, approaches and consideration when developing apps from prototypes to large scale projects.
• Quick look at some of the Adobe and 3rd party Application micro-architectures
• Get into some code
• Explore 4 different stages of a single application: Yahoo! Image Search app• Balance of rapid prototyping with scalable architectures
• Go home and watch the debates!
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
a little about me…
Early days
B.S. in Computer Engineering from Georgia Tech
Java as first (programming) language…then worked with EVERYTHING else
Started work in the ‘real world’ at 19 - Siemen’s Telecom and Motorola
Built my first Flash (4) sites in ‘97. And yes, a couple had skip intro movies…
Life in the Wild
Graduated in August. Career Fair on Sept 10th & 1111thth … 2001.
Good grades gave me a choice: $$$ || knowledge. I chose the latter.
Helped start an enterprise J2EE Portal with Federated Dept. Stores.
Art School on the side - Interactive Media Design
Started with Flex 1.0 Presentation Server. Flex as a JSP taglib?!
Livin’ Large
Began work as a Flex contractor…overtime pay is great.
Enterprise VOIP UI Team Lead with BellSouth
(Flash 8 + AS2) * Large Enterprise App = Pain
Senior Technical Architect + UX Designer = Nirvana
I’d love to show you what I’m working on right now, but then I’d have to ki…
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
a little about you…
With a show of hands…
How many of you have worked with Flex before?
If yes, how much experience? 6 mo. or more? A year or more? 2-3? Pros?
If no, how have you heard about it or become interested in it?
How many have worked with Flash but are new to Flex?
How many come from a different background and work with Flex only a little or are just learning?
Java?
Web? (HTML, JavaScript, CSS, AJAX)
Other?
Anyone not interested in Flex? …maybe in an hour or two you’ll change your mind!
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
Key data service classes and how they interact
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
To listen? Or to respond?
Listening• Event subscription through addEventListener() establishes a relationship between a dispatching class and a receiving function until removed.
• Its like getting into a committed relationship with a person. You have to listen to every single thing they say even if you didn’t ask for it! It only ends when you break it off.
• Consider listening to service results only when you are certain that your event recipient is truly interested in processing ALL of the responses.
• Fault handlers are often listeners even when associated response handlers are responders.
• Responders are associated with a particular request using AsyncToken’s addResponder(). They only get called once in response to the request for which they are associated.
• Following the relationship analogy, I guess this would be like ‘friends with benefits’. If you give them a call, they’ll be there in a heartbeat, but otherwise they just leave you alone!
• Consider responding to service results when you need to process individual requests or you are building a (stateless) common service that must handle multiple, simultaneous requests.
• Responding can occur at multiple levels.
Responding
As with many decisions related to software architecture and design, there isn’t just one ‘right’ way to interact with data services.
Instead, you have a number of supported interactions, each of which has its own place and purpose.
The two primary interaction patterns are: (Event) Listening & Responding (to a request)
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
mx.rpc.AsyncToken
The AsyncToken class:
• Is a dynamic object that is returned from the send() method of service classes• Serves as the conduit between an asynchronous request and its corresponding
response.
Three fundamental benefits to using the AsyncToken:
• A simple means for the consumer of a service to interact with only the request it initiates.
• A persistent object associated with a service request that can be shared with multiple parties (classes, etc.) that are interested in participating in the processing of the response without their explicit involvement in the request itself.
• As a dynamic class, it can provide the correlation of a service request’s input data, or other similar contextual information, with the associated response.
public dynamic class AsyncToken extends EventDispatcher {public function addResponder(responder:IResponder):void;public function get result():Object;public function hasResponder():Boolean;
}
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
mx.rpc.IResponder
package mx.rpc {
/** * This interface provides the contract for any service that needs to respond to remote or
asynchronous calls. */public interface IResponder {
/** * This method is called by a service when the return value has been received. * While <code>data</code> is typed as Object, it is often * (but not always) an mx.rpc.events.ResultEvent. */function result(data:Object):void;
/** * This method is called by a service when an error has been received. * While <code>info</code> is typed as Object it is often * (but not always) an mx.rpc.events.FaultEvent. */function fault(info:Object):void;
}
}
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
mx.collections.ItemResponder
package mx.collections {import mx.rpc.IResponder;
public class ItemResponder implements IResponder {public function ItemResponder(result:Function, fault:Function, token:Object = null) {
super();
_resultHandler = result;_faultHandler = fault;_token = token;
}public function result(data:Object):void {
resultHandler(data, _token);}public function fault(info:Object):void {
faultHandler(info, _token);}
private var _resultHandler:Function;private var _faultHandler:Function;private var _token:Object;
}
}
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
A Tale of Two Tokens
AsyncToken
• Dynamic class created by a service when a request is made through the send() function.
• Can be passed to multiple classes interested in the transaction (Services, Views, Controllers).
• Each class that has access to the token can participate in the response (result or fault).
• As a dynamic class, each and every responder can interact (mess with) dynamic properties.
• Both a Pro and a Con!
ItemResponder’s data token
• Optional parameter in the ItemResponder’s constructor.
• Typed as Object, so it can be just about anything you want it to be.
• Provides a means of establishing local contextual data for a response (result / fault pair)
• Since it is a local, dynamic object, nobody else can mess with it!
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
Keeping data parsing at the service level
Problem
So, you followed the best practices of MVCS and created:• Service Façade Interfaces - abstract service details and centralize service
processing. Translate response data (XML) in to Data Models and vice-versa.
• Strongly-type Data Models - common data structures that insulate Views from service and schema changes.
If I use AsyncToken as the return value for all of my services, then don’t all of the components that receive the response have to translate the raw data into models?
How do I keep that encapsulated in the service classes?
Solution
The service establishes itself as a responder. It will be called first since it registers first.
The service then translates result data into models and attaches them to the token.
Each subsequent responder now has access to the pre-processed models.
Caution
This solution relies on non-typed properties of a dynamic object as the contract between the service and its consumers.
Each consumer (responder) has the opportunity to mess with the dynamic properties that subsequent responders rely on.
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
Multiple Participation (Is that even
allowed in this state?!)
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
Many other options
Many Flex-based Application Frameworks exist that provide similar or enhanced capabilities beyond what is capable with the standard Flex 3 framework components covered today.
Some popular application frameworks:
Cairngorm micro-architectureFree. Originally conceived by iteration::two who later became part of Adobe Consulting.http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm
PureMVCFree. Two version available: Standard & MultiCore, which supports multiple PureMVC apps in 1 VM.http://puremvc.org/
Model-Glue: Flexhttp://www.model-glue.com/flex.cfm
ServeBox Foundryhttp://www.servebox.com/foundry/doku.php
Guasaxhttp://www.guasax.com/blog/
MateMate is a tag-based, event-driven Flex frameworkhttp://mate.asfusion.com/
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
Lets see some code already!!!
© 2008 AT&T Intellectual Property. All rights reserved.
AT&T and the AT&T logo are trademarks of AT&T Intellectual Property.
Sites referenced during the presentation
Ely GreenfieldArchitect on the Flex SDK TeamQuietly Scheming: http://www.quietlyscheming.com/blog
Doug McCuneUniversal MindBlog: http://dougmccune.com/blog/
Programmable WebMashups - Web 2.0 APIs - Web as a Platformhttp://www.programmableweb.com/Yahoo Image Searchhttp://www.programmableweb.com/api/yahoo-image-search
Flex 3 Regular Expression ExplorerCreated by: Ryan SwansonBlog: http://blog.ryanswanson.com/2008/10/introducing-flex-3-regular-expression.htmlApplication: http://ryanswanson.com/regexp/