microarchitecture, , " />

FlashPlatformist
Articles, Information, News, & Tutorials for Adobe Flash Platform Developers and Architects

Second Generation Micro-architectures, Part 1: The Swiz Framework

Second Generation Micro-architectures

One of the primary reasons we have microarchitectures and design patterns in the first place is to maximize simplicity in application code. The problem is that not every architect understands this. Often we find architectures and design patterns being used in ways that do nothing more than increase complexity, which is counter-intuitive. This is why it is important to understand the framework that you are working with before you begin development on a production project that uses it, and Swiz is no exception.

A common characteristic among second-generation micro-architectures is that they are built to empower the developer, rather than over-power. One thing that all of these second-generation microarchitectures have in common, is that they use some form of Inversion of Control (IoC) and Dependency Injection, as defined by the great Martin Fowler in his book Patterns of Enterprise Application Architecture (Addison Wesley, 2002). With that in mind, you will first learn a bit about how these design patterns work from a conceptual standpoint before you get your hands dirty.

A Quick Background on Inversion of Control & Dependency Injection

Generally speaking, a good microarchitecture should allow the developer to decide how to implement an effective model based on the unique characteristics of the application. As previously stated, it should never force the developer into a specific model implementation. The Flex Framework is largely based on principles of Inversion of Control (IoC). In fact, this is true for most event-driven user interface development toolkits and frameworks such as Java Spring, EJB 3, Spring.NET, the ColdSpring framework for Coldfusion, Needle for Ruby, and FLOW3 for PHP 5.

The Inversion of Control pattern originally comes from another pattern described in a very important book published in 1995 that is often referred to as the “gang of four” or “gof” book, titled Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley). If you do not have this book already, I strongly suggest you add it to your collection as it considered a staple by every good developer I have ever met. One of the 22 design patterns described in this book is the Factory Method Design Pattern. IoC is a derivative of this pattern.

Why does ActionScript works well with IoC?

As you have learned, the ActionScript language is an object-oriented language in which objects are instantiated by declaring new instances, like so:

private var thisObject:ThisObject = new ThisObject(params...);

In contrast, IoC instantiates and registers a specific set of pre-defined objects at runtime, and injects them into each other using a concept known as Dependency Injection. By injecting these dependencies at runtime, the dependencies can be quickly and easily modified because the objects remain loosely coupled. The objects are loosely coupled because their dependencies are not “hard-coded” into the classes. This makes managing large code bases much easier.

Objects and object properties can then be wired up through binding. That means that all of your views and components can have what they need before anything ever even shows up on the stage!
With other implementations like Java Spring, an application’s objects and implementations can be declared in an XML document.  However, this particular method is not possible with Flex due to the order of operations that happen at application startup. More specifically, an application is not ready to parse an XML document until after it’s objects have already been instantiated.

Coding Flex Applications with Swiz

Swiz caters specifically to enterprise level Flex development by providing a solid architectural foundation derived from proven enterprise application development patterns. This includes:

  1. Minimizing dependencies to promote loose coupling
  2. Inverting the flow of control
  3. Dynamic mediation

Swiz meta data: Autowire

The Autowire tag is used for component wiring, while the Mediate tag is used for dynamic mediation of events during the bubbling phase of the event cycle. Placing the Autowire meta data above the property of an object tells Swiz that it should inject a specified property from another class into this property. This is written as follows:

[Autowire]
[Bindable]
public var mainViewPModel:MainViewPresentationModel;

In the example above, the MainViewPresentationModel class is injected at runtime by Swiz as a result of the Autowire tag being placed above it. It is also made bindable in this instance so it can be referenced from properties of MXML components. Let’s say you have a Boolean property in MainViewPresentationModel called calendarVisible. Then, let’s say that when the application enters a certain state, calendarVisible gets set to true. (Note that calendarVisible should also be bindable in this case). In the MXML view that has the presentation model autowired into it, you could now state the following:

 <components:CustomCalendar id="calendar" visible="{mainViewPModel.calendarVisible}" />

Ok, so what’s so special about that? Well, now let’s say you have an event called mainStateChanged, which is mediated in the controller class (more on event mediating in a moment). When the event is fired, the controller that is mediating it picks it up during the bubbling phase, and initiates the setting of calendarVisible to true. Since we’re binding to that value in the visible property of the component, the calendar will immediately become visible! Ok, now that you’ve got that figured out, it’s time to learn about mediating events.

Using the Mediate Tag

The first and most important thing I should note in regard to using the Mediate tag, is that events should ONLY be mediated in controller classes. If you place Mediate tags all over the application, mediating events in the model and the view for example, your application will be seem just as much like spaghetti-code as it would if you used no framework at all. Remember that Swiz gives you much flexibility, but with that flexibility comes a responsibility to use best practices when writing your code.

If you are already familiar with the publish-subscribe design pattern, then understanding event mediation should come fairly easily. The following code demonstrates the use of the Mediate tag:

[Mediate( event="DataEvent.SHOW_DATATIP", properties="index,data" )]
public function showDataTip( index:int, data:ArrayCollection ):void {
   var itemData:String = data.getItemAtIndex(index).toString;
   var dataTip:DataTip = new DataTip(itemData);
   addChild(dataTip); }

In the example demonstrated above, Swiz will always be listening for the DataEvent.SHOW_DATATIP event during application runtime. When Swiz finds a Mediate tag, it binds the specified event to the method that appears on the next line. When the event is fired, Swiz automatically calls that method.

In order to declare events with the ClassName.CONSTANT syntax as it is in the example code, you must tell Swiz where your events are located using the eventPackages property of the SwizConfig object that you declared in your main application file. Otherwise, you will need to use the fully qualified path when specifying the event that should be mediated.

Possibly Related Posts:



Posted by Dan Orlando on March 14th, 2010 :: Filed under Enterprise Flex
Tags :: , ,

Using the Zend Framework to take some wind out of AIR

If you have worked at length with the Zend framework for PHP, you already know that it can do just about anything you could possibly need it to. With that in mind, it is not surprising to find that Zend will talk to almost any web service available, and it’s all built right into the framework. This is ideal when you want to build a truly “thin” client, where the code for the user interface is actually specific to the user interface and the business logic is abstracted into an entirely separate layer. This allows for maximum code reuse as well as multi-tier enterprise scalability and ease of deployment.

In some respects, the Internet cursed the enterprise because it caused developers to abandon rich, client-side user interfaces in favor of advantages such as version management that they had on local networks. The Adobe Integrated Runtime (AIR) is a desktop application development tool that is conducive to enterprise software development simply for the fact that the only code that needs to reside within the client application is that which pertains directly to the user interface. Therefore, a powerful language and framework like PHP and Zend can hold the business logic for server-side processing before handing the data off to the client. When combined with the Action Message Format (AMF) protocol for rapid data transfer, you end up with a seriously powerful enterprise-grade desktop application that’s hooked right into the Internet.

This brings up an important point: just because a code library or Software Development Kit (SDK) already exists for ActionScript that does the same exact thing as the Zend framework’s implementation, does not necessarily mean that it should always be used. Nine times out of ten, the users of your Flex or AIR application will be pleasantly surprised to find how smoothly it runs when you optimize your database and cache the information on the server, while using AMF or RTMP to transfer compressed, binary data packets between client and server.
Some may argue that this will increase costs associated with bandwidth consumption in an enterprise environment. This is true. At the same time, AMF is the most efficient protocol standard available right now, and the cost to the company is a fraction of the cost compared to using REST or SOAP.

Enterprises waste a lot more money by scaling hardware in clustered network infrastructures rather than moving to Cloud-based solutions right now anyway, so the credibility of that argument is questionable.

Possibly Related Posts:



Posted by Dan Orlando on August 23rd, 2009 :: Filed under Enterprise Flex
Tags :: , , , ,

Thinking Outside the IDE: Ideas for Flex Architects

After completing the planning phase of the software design lifecycle, it is usually a good idea to test your architecture before the programming begins. You might be wondering – how do you test an architecture without doing any programming? Well, here’s one way you can do it:

Try conducting a series of role-playing exercises with the development team.  This should be a fun exercise, so be careful not to impose any rigid rules on the game. First, give each person a piece of construction paper and markers. Next, conduct the exercise by providing the team with a use-case scenario that fits the context of the application that has been assigned to the team.  Allow them to brainstorm the solution using the architecture that you created as a guide. They should decide who plays what role, based on the elements of your architectural diagram. A role could be an object, a data or series of data packets, an event, an event dispatcher, etc. Each person should then write down the name of their role on the piece of construction paper they were given and hold it up while acting out the use case scenario.  The only requirement is that the developers involved need to first understand the architecture, or it will result in confusion and frustration.  They must also be familiar with basic object-oriented principles so they may communicate effectively, especially if they run into a situation where your architecture fails.  The team must then brainstorm possible solutions to the problem.

This is a solid, low-cost way of putting your architecture to the test before the application development process starts.  During their performance, you will likely find them discovering what will and will not work for the application while they interact with each other. Expect to be surprised by unexpected results that the team will encounter during the performance (like bumping into each other while performing a task, being in the wrong place at the right time or vice versa, etc…).

This type of multi-sensory problem solving has proven to enhance learning and problem solving skills at an incredibly rapid rate in education, and a number of related studies have been conducted in the field of Psychology to fully understand just why this works so well. What researchers have found, is that it facilitates a “rewiring” of the brain, effectively bridging the gap between the right and left hemispheres.

Development Styles and Methodologies

Enterprise level application development is extremely complex and researchers have had a terrible time identifying the specifics of why so many large-scale software projects fail.  However, a more generalized approach would suggest that it is due to having a constantly changing environment. This includes: changes in business requirements in the middle of the project, swapping developers in and out of projects like monkeys that bang on keyboards all day, budget cuts, and a lopsided team with regard to skill sets. With regard to the latter, it is common to find small development teams with too many “experts”.  Remember, you need people to worry about the trees too, not just the forest.

The latest development methodology (warning: buzzword ahead) is commonly referred to by the term agile development.  Agile development is a “best practices” type of approach that supersedes prior attempts at creating a universal development model such as “extreme programming” and “Rational Unified Process”, among others.  Every time I hear a Technical Lead or Project Manager say “we use the agile development method”, I am reminded of Einstein’s definition of insanity: doing the same thing over and over, yet expecting a different result each time.

As a science, computer programming is quite immature, and it therefore suffers from the same concepts and theories right now that once existed in the early years of every science, each of which we now look at as being totally ridiculous. For example, it was once thought that the earth was the center-point of the universe.  We can even find some disturbing theories and practices in the field of Medicine. In the 1400’s, it was believed that bringing the sick back to health meant “bleeding” the illness out the individual.  As a result, a mere sinus infection could cost you your life thanks to what was then considered “modern medicine”.

The history of other sciences and what was considered to be “best practices” must be taken into account considering the age of the science of computer programming. Agile development, for example, favors experts in the field to a great extent, which is comprised of maybe 2% to 5% of the computer programmer population. By definition, Agile Development uses feedback to make constant adjustments in a highly collaborative environment.  The problem with this is that the ability to self-correct based on previous experiences is only possible at higher skill levels, where the developer is able to observe an application as an objective whole, not just the little pieces that she constructed. According to Andy Hunt in his book Pragmatic Thinking and Learning, “Advanced beginners and competent practitioners often confuse design patterns for recipes, often with disastrous results.”

Possibly Related Posts:



Posted by Dan Orlando on April 5th, 2009 :: Filed under Enterprise Flex

Micro-architectures for Flex Enterprise Development

The key to writing solid enterprise Flex applications is to fully understand the overall architecture of Flex as a framework, as well as the various design patterns contained within it. By maintaining consistency between your micro-architecture and the Flex framework’s architecture, the application design and development process is guaranteed to be smooth, effective, and simple.

I must first point out that there exists a significant different between an application framework and a micro-architecture.  Flex is an application framework based on ActionScript 3.0, whereas Cairngorm – for example – is a micro-architecture for Flex. Currently, there exist two architectural frameworks for Flex that are in full release; Cairngorm and PureMVC.   Micro-architectures are good for three primary things:

  1. They provide a starting point for the architecture of a software program
  2. They establish a set of standards to be followed during development
  3. Standards lead to consistency, which makes the code within enterprise applications easier to maintain and add new features to later


Understanding Flex Architecture

The first thing to know as an enterprise Flex developer is that Flex is based around the Model-View-Controller (MVC) architecture. MVC became popular in 1995, when SmallTalk was the language of choice for a large portion of client side application development.

The second thing to know is that MVC is a global architecture in that it is a model that is meant to represent an entire body of code, whether it is an application or an application framework.  In other words, it is a method of organization for a large amount of code. Therefore, expect to find a number of design patterns contained within an application or framework that models MVC architecture, including Flex.

These design patterns depend entirely on the problems that must be solved with the application or framework. It is therefore theoretically possible to have billions of architectural frameworks for a single language, all based on the same MVC structure. However, the problems we encounter in enterprise software development tend to remain relatively constant (although they to evolve and change over time), and therefore it is unlikely that we would ever see that happen (although J2EE does have 72 so far!).


Cairngorm

Cairngorm is a micro-architecture for enterprise Flex applications initially created by a company known as Iteration II, which was bought by Adobe Systems and merged with Adobe Consulting.  Since then, Adobe Consulting has made strong efforts at focusing the continued development and maintenance of Cairngorm around that of Flex. It is for this reason that Cairngorm is worth more than just a look when considering a micro-architecture for your enterprise Flex application. Furthermore, if you’ve already commenced development on an enterprise level Flex or AIR application and you’re just reading this now, not to worry. The Cairngorm documentation does an excellent job at explaining in a step by step process how to go about integrating the Cairngorm framework into an already existing enterprise Flex application.

Iteration II was a firm that did much of it’s development in J2EE. As a result, Cairngorm implements a number of design patterns that are most popular in J2EE development. With that in mind, Flex developers that come from an enterprise Java background should be able to get used to Cairngorm fairly quickly and easily.  Even if you don’t have an enterprise Java background, Cairngorm is still an easy platform to understand as long as you are familiar with basic object-oriented programming concepts and design patterns.

Some of the more distinguishing factors of Cairngorm include the use of a central event and central event dispatcher, and the use of business delegates. Cairngorm is centered largely on the use of the observer and command design patterns and does a pretty decent job overall with regard to abstraction and encapsulation of code.

The strongest criticism against Cairngorm has been that it implements J2EE design patterns that are “force-fit” into the application architecture. An example of this is the use of business delegates.


PureMVC

The PureMVC micro-architecture focuses on maintaining strict adherence to the MVC architecture.  PureMVC actually started as an enterprise architecture for ActionScript 3.0 including Flex, Flash, and AIR. The architects soon realized that their architecture could apply to a number of other languages as well. Since then, versions of PureMVC have been created for C#, ActionScript 2.0, ColdFusion, Haxe, Java, JavaScript, Objective C, PHP, Python, and Ruby.

The most obvious characteristic of PureMVC is that it relies heavily on the Singleton design pattern, in that there exists a Singleton class that holds all references for each of the three MVC layers.  Whereas Cairngorm relies on “value objects” for data transfer (also known as DTO’s or Data Transfer Objects in Java), PureMVC uses proxies to manage data objects.  Other design patterns used in PureMVC include: Façade, Mediator, and Command.

The biggest argument against PureMVC is the lack of true abstraction and encapsulation due to the fact that pretty much any object or class can access any other object or class. The Singleton design pattern is probably the most controversial of design patterns among architects due to the fact that Singletons and Multitons are not necessarily meant to be used liberally, and should only exist for certain specific instances. It is therefore argued whether or not PureMVC is truly using what is considered to be “best practices” in the world of software architecture and design patterns.


Alternatives to Cairngorm and PureMVC

Comparatively speaking, AS3, Flex, and AIR are in their early stages of evolution, as are most technologies that fall under the RIA classification.  For example, JavaEE has over seventy different architectural frameworks available, each of which is focused on solving a specific type of problem. This supports the argument that there is no “one size fits all” solution, which is what both Cairngorm and PureMVC attempt to be.  If this were true, there wouldn’t be a new architectural framework released for J2EE practically every month.

Most Flex developers are still coming to grips with the architecture that is contained within the Flex framework, so it has not become common practice yet to propose new architectural frameworks for enterprise Flex applications.  It is noteworthy however, to point out one exception, called Fireclay.


Fireclay

Shashank Tiwari, a well-respected software architect and author in the Flex community, is the sole author of the Fireclay framework, which is currently in its infancy.  It is however currently available on Google Code, and well worth consideration for your next enterprise Flex application.  His most recent book, Advanced Flex 3 (Friends of ED), describes Fireclay in further detail in the first chapter. Other than that, there is little documentation, although the author has promised to provide a fair amount of documentation and explanatory examples in the near future.  The code is well commented though, so experienced architects should be able to quickly come to grips with this framework. If you do decide to use Fireclay as a starting point for your next enterprise Flex application, I strongly recommend that you pick up Advanced Flex 3 and use the first chapter to help you understand the underlying concepts that drive the Fireclay framework.

There are several notable differences that make Fireclay stand apart from Cairngorm and PureMVC.   Fireclay goes beyond the traditional page-based web architecture constrained and governed by the HTTP protocol and attempts to leverage the benefits of the thick and rich client. To start with, it provides a clear separation of the interaction and business logic from the view and model elements. It accomplishes this by placing the commands and services on the controller layer of the MVC architecture and uses an “event bus” for communications between the model, view and the controller.  The “event bus” facilitates the implementation of the event collaboration design pattern and realizes the loose coupling goals of a scalable and modular application.

Additionally, models are separated into two categories, a “local model” and a “proxy model”. This allows for appropriate source binding, caching, paging and lazy loading of data. For large applications, the framework provides registries to catalog commands, services and model elements. This reduces complexity and avoids code clutter and obfuscation. The views are assisted by helpers where required and are updated on model change events. The views read model elements and updates using the traditional observer-observable pattern.  This is consistent with the Flex framework, and as previously stated, consistency between the design patterns used in the Flex framework and that of your enterprise application architecture is a primary key to success.


Roll Your Own Architecture

The other alternative option you have is to roll your own architecture. In order to do this however, you should – at a minimum – have a firm understanding of the 23 architectural design patterns as outlined in the book titled Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, Helm, Johnson, Vlissides; Addison-Wesley; 1995). If you do not have this book, then get it…Now.

Additionally, you must have experience working with the Flex framework from an architectural standpoint and understand the design patterns that are used within it so you can maintain consistency with it in your architecture.

Lastly, and most importantly, don’t succumb to the false authority of tools or models. There is no substitute for creativity, intuition, and inventiveness. Keep in mind that the context of the application is critical. There comes a point where architectural rules are counter-productive.

Generally speaking, the time it takes to come up with workable solutions within your architecture depends on how complex the problems are that it is responsible for solving.


Conclusion

It seems quite common these days to mistake such micro-architectures for being a one-size-fits-all set of rules and methodologies that must be blindly adhered to and precisely followed. This type of mentality is counter-productive and stifles creativity. Every application is full of unique problems that require unique solutions, and to think that there is any “one size fits all” solution to enterprise application development projects is just pure ignorance.  It is therefore important to use your best judgment based on the situation when choosing how to approach an enterprise level software development project, and Flex applications are no exception.

Possibly Related Posts:



Posted by Dan Orlando on March 31st, 2009 :: Filed under Enterprise Flex
Tags :: ,

Understanding Flex Communication Protocols

Developing enterprise applications with Flex or AIR often requires a paradigm shift, regardless of your development background.  For web developers, it is the shift from stateless development to stateful. For Flash designers and AS2 developers, it is the painful realization that most of your programming up to this point hasn’t exactly been what is commonly referred to as “object-oriented” and a steep learning curve may lie ahead. For Java developers, it is the fact that although ActionScript 3.0 sometimes looks much like Java, this can be deceiving when developing enterprise applications with Flex and AIR.

For all intents and purposes, this article should serve as an informative resource for both Flex developers and technical business managers.  The goal is to provide a high-level view of enterprise Flex and AIR development, and assist with a global understanding of the technologies involved and when they should and should not be used.


Client-Server Communication

Choosing a server side language and communication method with Flex and AIR depend largely on facets of the business that are rarely taken into consideration by most developers. Usually, the technical decision-makers or lead architect will choose the technology that she knows best. This sometimes leads to disastrous results. The key to success here is to focus on the business model, and the tool will present itself.


Language doesn’t matter

While each server side platform has it’s own costs and benefits to the business; the Flash Virtual Machine really doesn’t care what is running on the server side. All it cares about is how the data is served up and whether or not it needs to deserialize it.  In fact, the FVM is usually completely unaware of what is running on the server side, especially if it is aggregating data from multiple sources.  That is the beauty of the separation between the server side business logic and the client side application that runs on the desktop or within the browser.  With that said, it is more practical to discuss method of communication.


Action Message Format (AMF)

The Action Message Format (hereafter referred to as “AMF”) is the binary data protocol officially supported by the Flash Virtual Machine. In other words, Serialization and Deserialization (otherwise known as marshalling and unmarshalling) of data objects is already built into – and is easily handled by – the Flash VM during runtime. AMF can be best described as a SOAP-RPC hybrid, in which data is transferred via Remote Procedure Calls. It is hard to place AMF in its own category here since it is really nothing more than an RPC protocol. However, the fact that it is the protocol officially supported by Adobe for client-server communications, and has built-in support with the Flash Virtual Machine makes it worth placing in its own category.

Advantages of AMF include: rapid data transfer, automatic marshalling and unmarshalling of data objects by the FVM, support across the entire spectrum of server side languages including .NET, PHP, Java, Ruby, and Python.

Disadvantages of AMF include: proprietary protocol that is not compatible with other client-side RIA development platforms such as DOJO, Scriptaculous, and SilverLight.  However, JavaScript communication via AMF with a server language is made possible through the Adobe AIR platform.
Requirements: Integration is fast and simple, and is made possible by integrating one of the following frameworks into your respective server environment:
PHP:  Zend, AMFPHP,  WebOrb for PHP, SabreAMF
Java: BlazeDS, Red5, GraniteDS, WebOrb for Java
.Net: FluorineFx, WebOrb for .Net, AMF.NET
Python: PyAMF
Ruby on Rails: RubyAMF, WebOrb for Ruby on Rails

Representational State Transfer (REST)

REST is built on simple http. However, support for RESTful services in Flex 3 is limited. Therefore, you will need to use either BlazeDS or a proxy in order to extend the Flex functionality for RESTful services beyond GET and POST.

Advantages include: direct communication with xml data sources, useful for web syndication

Disadvantages include: it is slow in comparison to the AMF protocol


SOAP, WSDL, RPC, and Everything Else

Most communication protocols (AMF included) are really just a REST-RPC hybrid that uses the http protocol in some way for request-response transfers. These types of communications are usually accomplished by simply calling a specific URI via the HTTPService class in Flex.

Possibly Related Posts:



Posted by Dan Orlando on March 31st, 2009 :: Filed under Enterprise Flex, Tutorials
Tags :: , , , ,

Enterprise Flex Model – v0.3

Version 0.3 of my new Flex enterprise development model got quite an overhaul. For those who are not familiar with the background of this posting, I am on an endeavor to create an alternative to Cairngorm and PureMVC for enterprise Flex/AS3 application architectures; particularly one which caters specifically to the Flex framework and is not based purely on J2EE best practices. A few points worth noting that I have yet to point out with this architecture:

The UIController

The UIController is meant to be a singleton class that provides access to the central event dispatcher (the event bus), as well as the model, which would likely be a getter for a centralized model class in the business library, which then has getters and setters for all the value objects contained in the model package. The UIController would be instantiated by the LifeCycleManager class, which would also have the responsibility of determining the application’s initial state (for example, if credentials are already in the encrypted local store and can be validated, go straight into the app without asking for credentials). The lifecycle manager also waits for a “MODEL_INITIALIZED” type of event, letting it know that any of the necessary client-server communications required prior to display of the initial application state are completed, at which point it instantiates the UIController. The UIController would also contain a command called something like “setBindings”, which would iterate through the bindingDictionaries package and set the bindings accordingly. With regard to this method of setting bindings, I still haven’t figured out how to handle non-instantiated view components with regard to this process yet. My objective here is to somehow centralize all of the bindings so that the developer can see how everything is “mapped” so to speak between view components and the data model. Technically, this is where the controller logic in the MVC pattern lies in this architecture.

Obviously there are some inherent issues that come with this.  My concern is that when an architecture has a substantial use of registries, the design patterns within the architecture become suspect.  However, it seems that it is most logical right now to use internal registries for services, commands, and events (although this may change).

Demarcation of the Business Layer

In the diagram, the demarcation of the business layer is quite clear, as I have now separated the architecture into two primary layers, one for business logic, and one for the actual GUI. For example, client-server communication and the construction of the model in the form of value objects happens within the business layer. Say for example that we have an AIR application that must ask the server if there are any tasks that have been created on the server side for it since the last time it ran. The server responds with a task to remind the user that their subscription is about to expire. That is then stored in the applications local sqllite db, and  the task is sent to a task handler queue to be handled in the background while the application is running.  When its time to handle the task, a notification event is fired, which goes through the event bus and displays the message in the UI.

Alternative Enterprise Flex Architecture - version 0.3

Alternative Enterprise Flex Architecture - version 0.3

If you have any questions and/or feedback, please do not hesitate to comment. Questions and comments are critical for identifying weaknesses with this architecture.

Possibly Related Posts:



Posted by Dan Orlando on February 12th, 2009 :: Filed under Enterprise Flex
Tags :: , ,

Enterprise Application Architecture for Flex and AIR – v0.2

I’ve updated my new proposed architecture for Enterprise level Flex and AIR applications. Although it is still nothing more than a single diagram, I am feeling more confident about it nonetheless. Not surprisingly, this version has inherited additional concepts used by Shashank Tawari and his Fireclay project, specifically the service registry. It seems to make a lot of sense to register all services in one central location, which can be used by the bindingDictionaries to bind classes in the command package as result handlers for services located in the serviceRegistry package. I’ve also incorporated a UIController class. For those that are familiar with J2EE or Cairngorm, this is not to be confused with the concept of the FrontController, as UIController acts more like a traffic cop. In the first iteration, UIController was abstracted in the business layer/logic, providing data model access. Instead, it’s purpose is now to simply be a mediator processes occuring within the user interface. It is also meant to be the single point of access for the event bus between the application layer/gateway and the abstracted functional libraries. You’ll notice the use of the term “library” instead of “layer” as well, in order to minimize confusion.

Proposed Enterprise Flex Architecture - v0.2

Proposed Enterprise Flex Architecture - v0.2

Possibly Related Posts:



Posted by Dan Orlando on February 8th, 2009 :: Filed under Enterprise Flex

The “Widget-based Programming Model” for Flex Enterprise Applications

I came across this article on O’Reilly’s InsideRIA site by Moxie Zheng and was surprised to find some similarities between the architecture the author describes and the architecture that I am seeking to create. The good stuff begins under the subtitle about halfway down, labeled “The Architecture”, where Moxie Zheng discusses his use of an Event Bus the same way as I have implemented it into my own architecture.

One thing I wanted to point out, and my reason for mentioning it here, is that below that he describes what he refers to as “The Widget Programming Model”, something I have not come across before. When it comes to enterprise Flex apps, we’re usually dealing with multiple user levels. In other words, the interface must look different based on the conditions under which the user is accessing the application. These conditions are often set by an external database server that handles user management, in which user types and their respective permissions may be set in a specific table. Then each user is assigned a user type, or in some cases, multiple user types. Therefore, the client side AIR or Flex application must construct itself “on the fly” so to speak, based on the group of configuration settings that it is handed from the server side. I like this widget-based programming model because it takes custom component development to an even more loosely coupled level, making it virtually impossible for the developer to creat interdependencies within an application due to the nature under which that particular widget must be programmed. It’s loose-coupling at it’s finest.

These “widgets” are compiled as separate swf “mini-applications” if you will, encapsulating and isolating code that handles a specific way of viewing data on the server. As I wrap my brain around the possibilities with this design pattern, I can’t help but think that for applications that are powered by specialized services, a “widget registry” could in fact be formed on the network (talking about AIR applications only now). Therefore, if a user was installing the application based on a certain set of credentials, a call to the network registry would return a set of “widgets” that should be installed along with the main application, thus defining how that particular user views the application interface. This concept could easily apply to the branding of an application based on the web site it was downloaded from, as a simple example.

Possibly Related Posts:



Posted by Dan Orlando on February 2nd, 2009 :: Filed under Enterprise Flex, Tools & Innovation
Tags :: , ,

New Enterprise Flex Development Model

This posting is in response to the comment left HERE, which I felt necessitated its own separate post and discussion. Before I start, I must first at least suggest that some research be conducted on Cairngorm, PureMVC, and Fireclay and allow yourself to draw your own conclusions with regard to how they fit into the bigger picture of your enterprise Flex or AIR project.

The first question that Jeff asks in his comment is if I can post a screenshot of a Flex directory structure of an enterprise application. My first thought was that I would make Jeff’s head spin if I did that due to the fact that every enterprise application I’ve worked on has had its own unique set of requirements, and differentiating the parts that could be considered as “standards-based” from those parts that were specific to the application (like a package titled “http” for RESTful services, for example) would not be of any assistance and would leave Jeff (and many others) right back where he started.

So instead, I drafted a diagram (figure 1) that so far seems like it could potentially be the bigger, better, faster, stronger framework for enterprise Flex development. Note that in order to address Jeff’s specific request, I made the diagram to be a sort of hybrid between a directory structure and a design pattern. This is the 50,000-foot view of the new architectural framework that I’m working on. Each rectangle represents a package or directory. Additionally, each layer is in fact it’s own library, with the exception of the Application Layer, which serves as the gateway to the application, and thus it is constructed as a standard Flex project and holds the primary MXML application file.

New Enterprise Flex Application Architecture

New Enterprise Flex Application Architecture

Notice that the different layers are completely unaware of each other. In fact, it is impossible, because if you attempt to add one of the libraries as a reference in the properties of another library, Flex Builder should throw a bunch of random “unknown errors” at you. This is because you have a cyclical redundancy in the build of the Application layer project (note that I am also addressing one of Jeff’s other points, which was to elaborate on the concept of separation of layers in the form of libraries).

In the diagram above, the application layer (which is the ONLY layer created as a Flex or AIR project, not a library project) holds references to the Business Layer, the Component Layer, and the Behavior Layer, which are all libraries and compile as separate swcs. During development however, I suggest you do not add the swcs to the libs folder of the Application Layer project, but rather add them as project references. Then, each time you build, you will notice that Flex Builder automatically recompiles each swc and adds them to the libs folder of your Application Layer project, as long as you have specified the libs folder in the “libraries” panel of the project properties. If you don’t do it this way, you will likely end up with “stale data”, meaning you’ve got an old swc from a previous build of one of your libraries, but the code in that library has been changed.

I must mention that the diagram above is merely a prototype, and has unfortunately not yet been put into practice. Therefore, I am open to feedback on it because, having been dissapointed in the past by Cairngorm and PureMVC, this is what I will be using for my next 2 enterprise level Flex development projects. At the same time however, this is only my first draft. The reason I drafted a diagram of a structure that has not yet been used in a real environment is for the simple fact that I would be doing Jeff – and everyone else that reads this – a disservice by showing you a diagram that is based on a past enterprise level project. This is because with each project, there were architectural decisions made that led to problems later. This is pretty typical when a new language is brought into the enterprise development space, and is to be expected.

The bottom line is that Flex and AIR are still very immature, and those of us who are using these technologies for enterprise development are still learning from our mistakes. Ultimately, we do our best and implement the design patterns we know, often from J2EE patterns since it bares the strongest resemblance to the Flex architecture. However, Flex (and AIR, and AS3 too for that matter) are unique in that they are event-driven. Therefore, a somewhat unique approach must still be taken to an enterprise Flex application that cater to it’s differences. This is why Cairngorm has a breaking point. Once an application becomes massive in size, a Cairngorm-based app turns into spaghetti-code and it becomes nearly impossible to track down events, event handlers, request-response handlers, etc.

Some Important Points

There are a few things I should point out about this initial draft shown above. First, it may not be immediately apparent, but it is in fact based on the MVC (model-view-controller) design pattern. The reason it is hard to tell at first glance is because we’ve got quite a few additional micro-patterns in here. For example, the “event bus” is based on the publish-subscribe design pattern, and I attribute Shashank Tiwari and his work on Fireclay for this idea. Shashank is developing Fireclay as an alternative to Cairngorm and PureMVC for many reasons, some of which I previously stated in regard to Cairngorm. The difference however, is that in the “bindingDictionaries” package – which is probably the most important to make note of in the application layer – is where the mapping of events to their respective handlers occur. This partially breaks away from how the publish-subscribe pattern is being used in Fireclay.

The relational size of the Business Layer/library in the diagram does not do justice for how large the business library will likely get in an enterprise Flex application. There is a lot of abstractions that must be made here and a significant amount of internal processing within this library. One of these abstractions I should point out is that the “model” package would contain a package within it called “vo” or “valueObjects”, which would basically hold references to all of our data as it is captured from the server.

Ultimately, there is a lot going on here and again, this is an over-simplified, high-level overview that encompasses my initial ideas for the architectural design pattern that I am working on developing right now. The important thing about it is that it resolves the many problems that I have seen come up in enterprise Flex development, whether it was a custom architecture being used or Cairngorm, or PureMVC, the problems that arise are consistent.  That is not to say however, that this is an end-all, be-all solution by any means….in fact, it is still just a baby.  However, I will soon find out where the weak points are as I continue to draw out additional diagrams to accompany this first iteration in my efforts of constructing a solid and robust architectural “best practices” standard for Flex enterprise development…well, at least for my own projects:)

Overall, I think the community is in great need of something that supercedes what is currently out there considering Flex and AIR are being used on such a grand scale all of a sudden for enterprise RIA development. I’m not sure if this is the start of something that will fulfill this need for the community, but at the very least it will give me what I need to make my future enterprise Flex projects successful.

There is one last point that Jeff makes in his comment, as follows:

“I’m struggling with the separation/inclusion architecture of these apps because most of them will have interdependencies – security, model, commands, etc.”

The answer here is to simply remove these interdependencies.  If this seems like a ridiculous and nearly impossible solution, then I might suggest that this project will be a nightmare for you until you decide on an architectural solution for this project and just accept the fact that you are going to have to hack away at the code in order to remove the interdependencies. In some cases however, interdependencies are ok. The simple rule with the solution that I have diagrammed above is that if the class doesn’t fit into any one of the 3 libraries, then it belongs in the Application Layer.

I hope this helps.

Possibly Related Posts:



Posted by Dan Orlando on January 26th, 2009 :: Filed under Enterprise Flex
Tags :: , ,

Flex and the Enterprise: Making Architectural Decisions

I currently have two very large Enterprise level Flex applications on my plate right now. The first is an overhaul of an already-existing application, where “best practices” and “design patterns” simply was an afterthought. The second application has not been built, as the company is in the process of raising financial support for it. Meanwhile however, I am in the process of creating the architectural structure for both of these. My first thought was to save some time and start with something that already exists. Here are my findings on my research:

Cairngorm

Every Flex developer has at the very least heard about Cairngorm. It is the brainchild of a company that was called Iteration Two, which was later bought out by Adobe and most of Iteration Two became the EMEA team of Adobe Consulting (This is why Adobe is constantly pushing Cairngorm down our throats).  Today Cairngorm is actively advocated by Adobe Consulting, the members of which are responsible for training Flex developers of large enterprises prior to transitioning company initiatives over to RIA. Thus, the effort to make Cairngorm the defacto standard for Enterprise Flex development is significant.

What’s Wrong with Cairngorm?

Cairngorm suffers from some inherent issues which, to me, were severe enough for me to move on, leaving Cairngorm behind. First of all, Iteration Two was a company focused primarily on J2EE development. If you are familiar with J2EE, go read the docs on Cairngorm. What you’ll find is that Cairngorm is nearly identical to the design patterns used in J2EE. While these design patterns work great for request-response Java apps and the J2EE world, some of these patterns were jammed into Cairngorm to solve certain problems, which are – in reality – a bad fit for Flex.

For example, the use of “business delegates” as they are referred in Cairngorm doesn’t completely make sense as this functionality is already handled inherently in the Flex framework. You also see a classic request-response pattern happening between the model and view layers using the Cairngorm FrontController class, similar to Java-style request-response programming between client and server. Additionally, all events must extend a central event, referred to as CairngormEvent, which is actually something that I think is a plus for Cairngorm, as this allow for a bit of organization among events. At the same time, it would have been nice if they called it “CentralEvent” and not CairngormEvent. Sometimes ego and branding get in the way of logical thinking I guess.

PureMVC

PureMVC really is exactly what it’s name implies. It is truly PURE mvc. In other words, it is so strict on the use of the MVC design pattern, that there is little room for implementation of other design patterns to solve other issues. The model-view-controller pattern is definitely the best central design pattern to use for enterprise Flex development. However, it is in no way in and of itself the end all-be all to enterprise flex apps.  This framework is also extremely dependent on the use of the Singleton design pattern, which I completely disagree with. Singletons should be used  VERY carefully, because in most cases, it’s use totally contradicts the basic principles of Object Oriented Programming.  It is for this reason that PureMVC was clearly not the answer in my quest, and so I moved on…which brought me to Fireclay.

Fireclay

Fireclay is by far the least known architectural framework for enterprise Flex development, and it is still in it’s infancy. Having been started by one  of my favorite auhors, Shashank Tiwari – whose most recent work is AdvancED Flex 3, published by Friends of ED (good read, I highly recommend it!) – the framework has not gotten much support yet from the community. I believe this is due to Fireclay being young, but also the fact that I think most people do not understand why Fireclay was born. You can currently find Fireclay up on GoogleCode here. The purpose of Fireclay, according to Tiwari, is to circumvent the inherent issues of Cairngorm and PureMVC. In order to accomplish this, it makes strong use of the publisher-subscriber design pattern. I immediately recognized Fireclay as being the closest thing to what I was looking for in an overall architecture to use for my upcoming projects.  Here are some of the notes that I took while studying Fireclay:

- It is hard not to notice the heavy use of the publisher-subscriber design pattern here…I’ve always thought of this as being a worthy alternative to having a billion events scattered throughout a massive flex app as i have seen in the past…eventually things just get out of control and some sort of event queue must be implemented.

- I like the event bus, as it has a built-in queue, which would be useful if the application state was “not ready” for example. A “not ready” state might mean that the application has not completed its initial communications with the server side that are necessary for startup.

- I like the idea of containing all services and events in a registry. This provides essential organization as the app grows.

- The event mapping methodology is interesting, and seems to allow the application to be extremely scalable. Binding tends to prevent loose coupling, and this type of “mapping” allows for enterprise developers to get away from being so heavily reliant on binding events and listeners if I am understanding this correctly.

It is evident that Fireclay is the closest thing to being worthy of the Enterprise Flex “best practices” Framework crown, but it is going to be a while before it is ready. Ultimately, it needs support from the community to complete it’s development. Additionally, there are a few things that Fireclay does not address….not yet anyway. Most importantly, it appears that it could benefit from the input of some of the advanced Flex architects in the community as it tends to overcomplicate some thing, which brings me to my last point…

Conclusion

The ultimate goal in architecting a design solution for an Enterprise level Flex application is to use the infamous K.I.S.S. theory….KEEP IT SIMPLE STUPID. However, that is also the greatest challenge for the architect…to ensure that every potential problem is addressed while still keeping everything as simple as is humanly possible so that future developers can walk in, look at a simple diagram, and know how the application works so they can start coding that same day. In essence, the architect must “see the future” so to speak and be able to predict the result of the architectural design pattern that they build and identify it’s weaknesses.

Java has 72 different frameworks, each serving a particular purpose for a specific type of application. Flex has 3 now (well, technically two and a half because Fireclay is only halfway there).  Unfortunately, it looks like I will need to develop a new methodology for enterprise Flex development because what is currently out there just doesn’t fit the needs of the applications I am responsible for right now.

Wish me luck (sigh).

Possibly Related Posts:



Posted by Dan Orlando on January 24th, 2009 :: Filed under Enterprise Flex
Tags :: , , ,