Design patterns suggest approach to common problems that arise during software development regardless of what programming language. But implementation of these patterns is specific to the language. The main goal of this presentation is to highlight selected patterns as they may be implemented taking advantages of Flex framework.
You'll see a not so obvious implementation of a Singleton, how a Proxy can dramatically change the behavior of an object, why a Mediator is a must-have in each Flex application. Do you know how to write Data Transfer Objects that are so important in Flex remoting? If time permits, we'll review the Class Factory pattern too.
2. Farata Systems: What do we wo
Consulting and training ($$$$$$$$$$$$$$$$$$)
Software development (for free)
(open source project Clear Toolkit on Sourceforge.net)
Writing tech. books and articles on Java and Adobe Flex
(making from $0 to $1 per hour)
www.faratasystems.com 2
7. Enhancing the ApplicaGon object
public dynamic class DynamicApplica5on extends Applica5on
implements IApplicaGonFacade{
public funcGon DynamicApplicaGon(){
super();
}
public staGc var services:DicGonary = new DicGonary();
public funcGon getService(name:String) : Object {
return services[name];
}
public funcGon addService(name:String,value: Object): void {
services[name] = value;
}
public funcGon removeService(name:String) : void {
delete services[name];
}
public funcGon getServices() : DicGonary { The IApplicaGonFacade just declares these
return services; four methods to enable Flex Builder’s
} intellisense help when casGng.
} var myApp:IApplicationFacade = …
(c) Farata Systems
12. How [Bindable] works?
[Bindable]
var lastName:String;
Flex compiler generates a wrapper class with a se*er
that dispatches propertyChange event on each
modificaGon of lastName
You can do it on your own by using the class
mx.uGls.ObjectProxy
(c) Farata Systems
13. Wrapping Person in ObjectProxy
package com.farata{
public dynamic class Person {
public var lastName:String=quot;Johnsonquot;;
public var salary:Number=50000;
}
}
(c) Farata Systems
18. Wall Street: Stock Trading ApplicaGon
Before the trader clicked on the Price Panel
PricePanel component has three
variables: symbol, bid and ask
PricePanel dispatches the OrderEvent
dispatchEvent(new OrderEvent(
OrderEvent.PREPARE_ORDER_EVENT
, symbol, bid,ask,buy));
OrderPanel listens to OrderEvent ACer the trader clicked on the Price Panel
addEventListener(
OrderEvent.PLACE_ORDER_EVENT,
orderEventHandler)
func5on orderEventHandler(evt:OrderEvent){
sym.text=evt.symbol;
operaGon.text=evt.buy?quot;Buyquot;:quot;Sellquot;;
price.text=(oper.text==quot;Buyquot;?
evt.bid:evt.ask); (c) Farata Systems
}
20. Custom Event OrderEvent
Too many user variables.
It would be a good idea to
encapsulate them in one DTO –
Data Transfer Object a.k.a. Value Object
The Mediator receives this event from PricePanel
and dispatches it to OrderPanel
(c) Farata Systems
21. The Mediator applicaGon
Listen to the OrderEvent
from PricingPanel
…and send it to
OrderPanel
(c) Farata Systems
24. PricePanel Component. Take 2
UI components are bound to
DTO properGes
startDataFeed()
emulates external data feed
Packaging a DTO inside the
event OrderEvent2
(c) Farata Systems