|By Jason Dolinger||
|July 15, 2009 04:00 AM EDT||
With the arrival of .NET 3.5, WPF and the RTM of Silverlight 2, .NET developers have more choices than ever for designing, developing and deploying compelling applications with rich user interfaces. However, there are other mainstream alternatives that don't fall into the .NET camp. When it comes to the RIA world, technologies such as Adobe Flex and Flash may seem more foreign to some of us then driving on the left side of the road would be to an American. However, given the need to work on a Flex project, we are actually quite well suited for the transition, more so in many cases than developers coming from a more traditional web development world.
First off all, why choose to use Flex anyway? If you are building an RIA to deploy through the browser, Silverlight would seem the logical choice for a truly custom and unique UI when ASP.NET and AJAX don't fit the bill. But there are certain situations where an enterprise may decide that going the Adobe route is the correct choice for the needs of a particular project. The primary motivation comes with an application that is being built for external consumers. The Flash plug-in currently has a 99% market penetration according to Adobe and that's hard to argue with. This will be changing as Silverlight continues to be adopted but it currently remains an important consideration. As an example, I was recently involved in building an RIA meant to be subscribed to by many large financial institutions. These types of clients do not typically have the freedom to install browser plug-ins at will. Something like the Silverlight plug-in would need to be deployed in a firm-wide rollout after many months of compatibility testing, while Flash has been standard for years. Aside from this reason, the Adobe AIR runtime makes for a compelling usage scenario where your application assets can be deployed both in the browser or standalone on the desktop, allowing reuse of the majority of the same code base. AIR has a sophisticated web-based deployment and versioning model as well. Some form of this is expected in Silverlight 3 but it is already a reality for AIR. Finally, if you have a set of graphical assets already designed for Flash and designers who are most experienced in this area, the Flash/Flex path may be the easiest way to get the user experience you are after.
If you (or your project manager/architect) have decided that it must be Flex, don't be discouraged. While learning any new platform is a non-trivial undertaking, Flex is not as foreign to .NET as it may seem. When I've conducted interviews for Flex positions, usually the candidate came from a history of Java web development. The Flex platform enjoys close ties with the Java community, from its Eclipse-based IDE, Java style package naming, and Adobe's support of its Livecycle Data Services and BlazeDS APIs for remote service integration. However, I believe that the learning curve is more natural coming from WPF or Silverlight than from Java, culture and IDE differences aside. Rich Internet Applications are closer architecturally to desktop applications written in C++, WinForms or WPF than the standard non-AJAX web application. The kinship between Silverlight and Flash is even closer. RIAs are persistent applications that maintain state, and call remote services to load and store data (usually through XML or JSON), rather than loading pages of HTML. As such, the patterns for architecting one should follow those of a desktop application deployed in an n-tier environment. Further, the major elements of the Flex platform will be quite familiar to any WPF or Silverlight developer. Flex contains an XAML-like markup language for UI layout, an OO language to glue everything together, a mature set of controls and layout panels, an analogous eventing system, databinding, and a DataTemplate like mechanism.
Introducing the Flex 3 Framework
Flex is the UI toolkit for building RIAs based on the ActionScript language and running in Flash player, as WPF and Silverlight are frameworks for building applications in C# that run in the .NET CLR or Silverlight runtime. As WPF has XAML, Flex has its own analogous language called MXML that serves the same purpose. It is a serialization language for describing your application views by constructing trees of layout elements and control elements, and setting properties on them. Your MXML files get compiled to ActionScript and the MXML tags that you declare create instances of AS classes. Flex does not have the same concept of codebehind as you'll find in the .NET world, but ActionScript can co-exist in the same file as your MXML markup in a special CDATA block for this purpose. This ActionScript is just another part of the class that the MXML in the file gets compiled into, so the overall effect is the same.
Many other WPF constructs have similar analogues in the Flex world. Flex provides an eventing model that anyone familiar with C# delegates and events will have no trouble understanding. Routed events have been a part of Flex for as long as they were in WPF. These events have a tunneling phase (called "capture") where they travel down through the control tree from the top level (called the Stage in Flash) to the target where the event occurred, followed by a bubbling phase where they travel up the tree, in both directions, looking for any registered event handlers.
Flex has a databinding mechanism for connecting UI controls to model data. The syntax is more awkward than you may be used to, but you can (and should) still make use of this for binding your view controls to their model (or viewmodel). Unfortunately there is no concept of a DataContext, so even if a single model object provides all of the underlying data for your view, you'll need to specify that in each binding expression path.
For giving a custom look to lists of data as well as DataGrid columns, Flex gives you a construct called an item renderer that is quite similar to our familiar DataTemplate. An item renderer is usually a small tree of MXML, but can be implemented as a class with some behavior behind it. When binding to a list of data, Flex uses the renderer as a factory to create additional instances of the same class, used to render each underlying model item in the list. Just as in XAML, your item renderers can be declared inline, separated out into separate component files or even built up in code. Item renderers in Flex only apply to list data. With the PresentationModel patterns being applied in .NET 3.5 now, views are often being abstracted into a simple ContentControl rendering dynamically based on the DataTemplate for the bound Content, but you won't be able to do anything quite that clever here.
Learning the ActionScript language will present no major hurdle for anyone experienced with C# or Java. ActionScript 3 (the current version) is based on ECMAScript 4.0, and is largely grounded in OO principles with the addition of some ideas from the functional world. It is a true object-oriented language supporting inheritance, polymorphism and interfaces. The language is somewhat more dynamic; however, there are no strongly typed arrays or lists and you can forget about generics. There are no explicit delegates or events (objects fire events by implementing the IEventDispatcher interface). But functions are first class objects that can be passed as method arguments, used most frequently for adding handlers for events. Functions can also be anonymously declared inline. Interestingly, the ActionScript Array class has a number of higher order functions such as forEach(), filter(), map(), and some() for applying a function over a list of elements. If you are already using LINQ extension methods and delegates, you'll have no problem figuring out what to do with these. The language does leave out a few of the common OO constructs that you've grown accustomed to, such as abstract classes, private constructors and static initializers. While you will miss them, they won't be anything that you can't work around.
Flex makes use of the Flash player threading model in which all of the code you write executes on the single UI thread, so forget about doing CPU-intensive processing while keeping your UI responsive. You can perform some I/O bound operations through a model similar to .NET's Asynchronous Programming Model though. Through this mechanism, you schedule an asynchronous action to be executed by the Flash player, such as calling a remote service or reading a file. You provide an event handling function to be invoked when the operation is finished so you can process the results, but this will be invoked on the same UI thread. While this model can be limiting, it does free you from worrying about thread synchronization or the need to marshal data between threads.
Perhaps the most initially disconcerting part of your switch to Flex will be getting used to a new development environment. The FlexBuilder IDE is based on Eclipse, coming either as a standalone install + the Eclipse shell or as a plug-in for existing Eclipse installations. Eclipse is a full-featured IDE when using it for Java development, and you get out of the box a similar feature set to what you have with Visual Studio + Resharper. But FlexBuilder does not support most of the more advanced refactorings, code organization, and generation tools that Eclipse users might be accustomed to. Therefore, you may feel that you are taking a step backwards when making the switch from Visual Studio. Most of your basic debugging tools are present (there are no conditional breakpoints but this is coming in Flex 4).
The story is more fragmented regarding the UI designer/developer workflow. Expression Blend has come a long way toward allowing designers and developers to simultaneously work on the same source tree and have a productive working relationship. Unfortunately there is no equivalent in the Flex world, and no tool that generates MXML, which can build and run the same projects used in Flex Builder. There is a built-in WYSIWYG editor in Flex Builder, but like the XAML designer in Visual Studio, it's not very useful beyond trivial applications. In general the flow between developers and designers is not as natural. Achieving more interesting effects, skins, and animations in Flex is often a combination of handwritten MXML combined with artifacts generated from tools such as Flash IDE, Adobe Illustrator, and open source libraries like Degrafa.
The Server Tier
As mentioned, the Adobe Flex community enjoys close ties with the Java world, and you'll find that a majority of Flex applications are served from and call remote services on a Java application server, or servlet engine. A large reason is that Adobe has released and supported a suite of APIs for integrating Flash Remoting with Java, through its AMF (Action Message Format) binary protocol. These products, BlazeDS and LiveCycle Data Services, provide a framework for exposing Java classes as endpoints for Flash Remoting and you get automatic mapping between your ActionScript and Java domain objects.
However, Flex is not in any way tied to Java, and you can easily serve a Flex application from IIS. Flex's HTTPService class asynchronously consumes XML, JSON or SOAP served from .NET Web Services, REST, or WCF. In this way you'll continue to use your IIS and .NET server infrastructure and skills, perhaps with a thin facade layer to serve the data in the format your Flex application expects. Furthermore, there is an open source implementation of AMF: FluorineFx. It comes complete with framework libraries and wizards for generating and configuring an ASP.NET web application that serves AMF. Writing a remote service for a Flex application becomes little more than writing your class and marking it with the appropriate attributes. I'd highly recommend checking out this option if you want to keep using C# on the server. AMF is more efficient than XML or JSON, and you'll have the power of using strongly typed ActionScript domain objects in your Flex tier without needing to write the mapping layer yourself. Pushing data to the browser is an option with Lightstreamer, RTMP, or sockets with a custom protocol.
Architecture and Design Patterns
As with any platform, architecture and design plays a larger role as the complexity of your application increases. This is one of the places where your existing experience will translate very well, and you'll be better off than Flex developers coming from the web world.
One of the biggest problems we need to circumvent is that of your entire application becoming housed within a few monolithic UI classes. The problem is even worse with Flex because, as mentioned, the code that you write along with your view can be put in a script block right in your MXML markup. This can be greatly abused just as code behind in WPF and other .NET platforms often is. I've seen more than one application consisting of a few grotesquely large MXML files with a few helper classes. Instead we need a way to write our applications in a clean and decoupled manner and achieve a proper separation of concerns.
There are a number of MV-x patterns used to provide basic architectural organization, often Model-View-Presenter for WinForms and Model-View-ViewModel (also called PresentationModel) in WPF. M-V-VM is the choice for WPF (over vanilla MVP) because of the platform's sophisticated databinding framework. As Flex also has a useable binding system, I've successfully applied M-V-VM to a large Flex project. The typical three-layer approach:
Service layer composed of classes that wrap Flash RemoteObjects (when using FluorineFx) or HTTPService classes for JSON or XML transfer. There should be service interfaces for all classes.
ViewModel layer that handles events from the views and exposes bindable properties that present a flat picture of the model data used in the view. These classes get injected with the service classes (of course talking to them through their interface to allow for mocking).
View layer composed primarily of MXML components with a minimum of ActionScript required to glue everything together. The primary purpose of this code is to create the ViewModel instance and direct event handlers from the UI controls into the ViewModel. Code that needs to stay very close to the view (such as drag and drop) can stay here as well.
I like to couple the above pattern with dependency injection to construct and inject instances of the viewmodel classes with their services and any other dependencies. This is still a rare technique in the Flex community, but is becoming more commonplace with several quite useable open source containers out there. SpiceFactory's Parsley and the Spring ActionScript container (formerly known as Prana) are great candidates for this.
Another architectural alternative is the Cairngorm framework, which is the Adobe approved framework for achieving the ideals set out above. You'll find many Flex projects that use it to varying degrees of success and pain. The main features of Cairngorm are a FrontController class with a set of commands that you write to handle the events, a ModelLocator singleton that provides a global access point to your model layer, and a ServiceLocator singleton for looking up instances of Remote Service wrappers. At first glance, Cairngorm feels a lot like a Java Struts MVC style framework (with FrontControllers and Commands), and may trick some more web developers into believing so, but this is not the case.
Cairngorm, like any framework, has some useful constructs and some frustrating ones, and one of the things that makes a framework useful is being able to incorporate the parts you want without making your whole codebase depend on the pieces you don't. While this is not a problem inherent in Cairngorm, many developers new to the framework utilize everything verbatim in the way that the tutorials and how-to's demonstrate. This tends to result in a congested code base with too much boilerplate code for Commands and Delegate classes, and lots of direct dependencies on the ModelLocater and ServiceLocator singletons. As we know that singleton classes are the enemy of flexibility and testability, this should make most of us cringe.
If you decide to leverage Cairngorm or take over a project already using it, remember to apply the good lessons you've learned in the .NET world. ViewModels are still worthy constructs to use with the framework, providing a place for handling events and exposing portions of your model that are local only to your specific component (they can be managed by the ModelLocator). Cairngorm is open source, so you can modify the FrontController to use your IoC container as the factory for your Command classes, so they are injected with the ModelLocator and service instances, rather than using the singleton method of accessing them. The Spring ActionScript container is already incorporating extensions to allow you to work around the messier parts of Cairngorm and is worth a look just for this reason.
As Silverlight and WPF mature and gain mainstream acceptance, Flex and Flash will undoubtedly be forced to evolve in a direction where they can stay competitive. It's likely that there will be further feature swapping and parallels between the two. If you do find yourself in a position where you or your team will need to work on a Flex application, don't feel that you will be throwing away what you know and starting from scratch. Rest assured that you will be in the best possible place to pick up the new framework as well as anyone, and can continue to build on the .NET infrastructure and support that you already have.
|cgehrke 07/09/09 06:30:00 AM EDT|
Thanks for your article. Your points are clearly explained and well thought out. Great job.
I am curious why you don't mention Adobe's latest design tool called Adobe Catalyst which has been in Beta and available for download for months now?
Adobe Catalyst is a new professional interaction design tool for rapidly creating user interfaces without coding.
I have been using Catalyst since December 2008 when I received a copy in Milan at the Adobe MAX Event. It's the perfect tool for merging the design world of Adobe to the developer world of Flex and Flash.
Using Catalyst, a designer can open and retain their artwork in a native format. No conversion or cutting up necessary. Just open your art file (PNG, PSD, AI) and retain your folder structure, effects and layers. You can then begin defining your elements so Flex knows what to do with them (IE: Buttons, Scroll Bars, Navigation, Etc,). Catalyst will write the Flex code for the developer under the hood. At any point you can switch back and forth from design to code view.
Adobe is known for it's great design tools: Photoshop, Illustrator and Fireworks to only name a few. It was only a matter of time until they found a way to merge the design world with the newly acquired developer world of which they adopted from Macromedia only 5 years ago. I am sure we've only seen the tip of the iceberg in regards to Adobe's full potential in the developer world.
Not to take away from your article in anyway, you did a great job here. Thanks for sharing.
WebRTC is bringing significant change to the communications landscape that will bridge the worlds of web and telephony, making the Internet the new standard for communications. Cloud9 took the road less traveled and used WebRTC to create a downloadable enterprise-grade communications platform that is changing the communication dynamic in the financial sector. In his session at @ThingsExpo, Leo Papadopoulos, CTO of Cloud9, discussed the importance of WebRTC and how it enables companies to focus o...
Jan. 20, 2017 08:45 PM EST Reads: 4,356
The Internet of Things can drive efficiency for airlines and airports. In their session at @ThingsExpo, Shyam Varan Nath, Principal Architect with GE, and Sudip Majumder, senior director of development at Oracle, discussed the technical details of the connected airline baggage and related social media solutions. These IoT applications will enhance travelers' journey experience and drive efficiency for the airlines and the airports.
Jan. 20, 2017 05:45 PM EST Reads: 2,089
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo 2016 in New York. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place June 6-8, 2017, at the Javits Center in New York City, New York, is co-located with 20th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry p...
Jan. 20, 2017 05:15 PM EST Reads: 3,805
"LinearHub provides smart video conferencing, which is the Roundee service, and we archive all the video conferences and we also provide the transcript," stated Sunghyuk Kim, CEO of LinearHub, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA.
Jan. 20, 2017 03:00 PM EST Reads: 1,649
Things are changing so quickly in IoT that it would take a wizard to predict which ecosystem will gain the most traction. In order for IoT to reach its potential, smart devices must be able to work together. Today, there are a slew of interoperability standards being promoted by big names to make this happen: HomeKit, Brillo and Alljoyn. In his session at @ThingsExpo, Adam Justice, vice president and general manager of Grid Connect, will review what happens when smart devices don’t work togethe...
Jan. 20, 2017 02:15 PM EST Reads: 618
"There's a growing demand from users for things to be faster. When you think about all the transactions or interactions users will have with your product and everything that is between those transactions and interactions - what drives us at Catchpoint Systems is the idea to measure that and to analyze it," explained Leo Vasiliou, Director of Web Performance Engineering at Catchpoint Systems, in this SYS-CON.tv interview at 18th Cloud Expo, held June 7-9, 2016, at the Javits Center in New York Ci...
Jan. 20, 2017 01:30 PM EST Reads: 5,732
The 20th International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held June 6-8, 2017, at the Javits Center in New York City, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Containers, Microservices and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal ...
Jan. 20, 2017 01:30 PM EST Reads: 5,236
Discover top technologies and tools all under one roof at April 24–28, 2017, at the Westin San Diego in San Diego, CA. Explore the Mobile Dev + Test and IoT Dev + Test Expo and enjoy all of these unique opportunities: The latest solutions, technologies, and tools in mobile or IoT software development and testing. Meet one-on-one with representatives from some of today's most innovative organizations
Jan. 20, 2017 12:30 PM EST Reads: 1,651
20th Cloud Expo, taking place June 6-8, 2017, at the Javits Center in New York City, NY, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy.
Jan. 20, 2017 12:30 PM EST Reads: 4,348
WebRTC is the future of browser-to-browser communications, and continues to make inroads into the traditional, difficult, plug-in web communications world. The 6th WebRTC Summit continues our tradition of delivering the latest and greatest presentations within the world of WebRTC. Topics include voice calling, video chat, P2P file sharing, and use cases that have already leveraged the power and convenience of WebRTC.
Jan. 20, 2017 12:30 PM EST Reads: 3,189
SYS-CON Events announced today that Super Micro Computer, Inc., a global leader in Embedded and IoT solutions, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 7-9, 2017, at the Javits Center in New York City, NY. Supermicro (NASDAQ: SMCI), the leading innovator in high-performance, high-efficiency server technology, is a premier provider of advanced server Building Block Solutions® for Data Center, Cloud Computing, Enterprise IT, Hadoop/Big Data, HPC and E...
Jan. 20, 2017 12:15 PM EST Reads: 5,839
Internet of @ThingsExpo, taking place June 6-8, 2017 at the Javits Center in New York City, New York, is co-located with the 20th International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. @ThingsExpo New York Call for Papers is now open.
Jan. 20, 2017 10:45 AM EST Reads: 3,705
WebRTC sits at the intersection between VoIP and the Web. As such, it poses some interesting challenges for those developing services on top of it, but also for those who need to test and monitor these services. In his session at WebRTC Summit, Tsahi Levent-Levi, co-founder of testRTC, reviewed the various challenges posed by WebRTC when it comes to testing and monitoring and on ways to overcome them.
Jan. 20, 2017 10:45 AM EST Reads: 6,093
DevOps is being widely accepted (if not fully adopted) as essential in enterprise IT. But as Enterprise DevOps gains maturity, expands scope, and increases velocity, the need for data-driven decisions across teams becomes more acute. DevOps teams in any modern business must wrangle the ‘digital exhaust’ from the delivery toolchain, "pervasive" and "cognitive" computing, APIs and services, mobile devices and applications, the Internet of Things, and now even blockchain. In this power panel at @...
Jan. 20, 2017 09:45 AM EST Reads: 2,936
WebRTC services have already permeated corporate communications in the form of videoconferencing solutions. However, WebRTC has the potential of going beyond and catalyzing a new class of services providing more than calls with capabilities such as mass-scale real-time media broadcasting, enriched and augmented video, person-to-machine and machine-to-machine communications. In his session at @ThingsExpo, Luis Lopez, CEO of Kurento, introduced the technologies required for implementing these idea...
Jan. 20, 2017 08:30 AM EST Reads: 4,765
Buzzword alert: Microservices and IoT at a DevOps conference? What could possibly go wrong? In this Power Panel at DevOps Summit, moderated by Jason Bloomberg, the leading expert on architecting agility for the enterprise and president of Intellyx, panelists peeled away the buzz and discuss the important architectural principles behind implementing IoT solutions for the enterprise. As remote IoT devices and sensors become increasingly intelligent, they become part of our distributed cloud enviro...
Jan. 20, 2017 08:15 AM EST Reads: 4,958
"A lot of times people will come to us and have a very diverse set of requirements or very customized need and we'll help them to implement it in a fashion that you can't just buy off of the shelf," explained Nick Rose, CTO of Enzu, in this SYS-CON.tv interview at 18th Cloud Expo, held June 7-9, 2016, at the Javits Center in New York City, NY.
Jan. 20, 2017 08:15 AM EST Reads: 4,725
The WebRTC Summit New York, to be held June 6-8, 2017, at the Javits Center in New York City, NY, announces that its Call for Papers is now open. Topics include all aspects of improving IT delivery by eliminating waste through automated business models leveraging cloud technologies. WebRTC Summit is co-located with 20th International Cloud Expo and @ThingsExpo. WebRTC is the future of browser-to-browser communications, and continues to make inroads into the traditional, difficult, plug-in web co...
Jan. 20, 2017 07:15 AM EST Reads: 2,983
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
Jan. 20, 2017 07:00 AM EST Reads: 9,085
For basic one-to-one voice or video calling solutions, WebRTC has proven to be a very powerful technology. Although WebRTC’s core functionality is to provide secure, real-time p2p media streaming, leveraging native platform features and server-side components brings up new communication capabilities for web and native mobile applications, allowing for advanced multi-user use cases such as video broadcasting, conferencing, and media recording.
Jan. 20, 2017 07:00 AM EST Reads: 6,879