CairngormModule Example

This is in no way a tutorial on Cairngorm… in-fact, the use of Cairngorm here is really rough. This is however an Application, using Cairngorm, that is split into Flex Modules. The important thing is the use of a Cairngorm implementation within the modules. 

For brevity I’m not using services. There are some important considerations with services and delegates. You can easily define the BusinessDelegates in the module package but in the structure I have shown, you must define the services in the main application.

In actual development, I use a custom implementation of ServiceLocator so that each modules can inject their own Service Objects. This gives me the ability to dynamically load modules at run time and makes the configuration stay where it belongs.

I hope that this small example helps people. I will probably move on to the architecture that I use most now, MVP (Model View Presenter).

The new me…

July 29, 2008

Ok, so it’s been a while. I’m sorry to those that were waiting for the cairngorm module examples. I don’t have a lot of time lately and I don’t use cairngorm so much now.

I hope to blog a bit more often now that I have a worspress app for my new iPhone 3G. I will be discussing the MVP pattern in my next few blogs and I will be doing a cairngorm compare and contrast.

If anyone still wants to see some cairngorm module code, let me know.

photo

Cairngorm Modularity…

December 7, 2007

Using modules in Flex isn’t all that difficult to understand. But as I have read on many a blog, using Cairngorm with modules is giving people fits. Well, not me…

You use modules so that you can load a portion of your application (functional or visual) and unload it independent of the main application. You do this (using Flex Builder) by extending mx.modules.Module either in a different project or the same, making sure your component is registered as an application in the properties. This Module Component then can be loaded into your main application (shell app) by use of the ModuleLoader class. Simply set the attribute ‘url’ on the ModuleLoader (which is a DisplayObject) and YourModuleLoaderID.loadModule() and YourModuleLoaderID.unloadModule(). If the module is a visual component it will be loaded wherever you place it. Likewise you can place a non visual module anywhere and reference it by id. This is where the difficulty starts.

Now that you have a loaded module, unless it’s a trivial thing, you are going to want to interact with it. With Cairngorm this is very interesting. All sorts of things can happen when you get an application running with the FrontController and ServiceLocator patterns then you just up and load an entirely autonomous Cairngorm implementation in the same player. So don’t. The interaction between module and shell application is communicated by implementing interfaces. If you are going to be using Cairngorm in the base or shell app, then you need to use IoC (inversion of control) to plug a Cairngorm based module into the shell. Specifically, your module will more then likely be using the FrontController to register events/command pairs and it will need to use the shell app’s ServiceLocator to access services. You can easily create an interface that allows you to pass these two items to the module being loaded and if your like me, you can even extend the Module component to make a lot of things happen in the background.

Read the rest of this entry »

What does Cairngorm do?

October 5, 2007

If you use Flex, then Cairngorm makes your life easier. Cairngorm makes your Flex programming more responsible, easier to maintain and extend and it promotes more efficient teamwork.

But what does it do?

Well, Cairngorm is a library (a compiled flash swf) of classes and interfaces that are plumbed together to allow the programmer to plug-in commands (control logic) and interfaces (views) in an easy, efficient manner. By using Cairngorm you are leveraging hundreds of thousands of hours of developer time figuring out what patterns work best for enterprise applications. The Adobe team used guidelines from the J2EE Enterprise Design Pattern catalog to create a very powerful framework (some say micro-architecture) for Flex distributed applications. This framework is logical so it is easy to learn and more importantly easy to teach.

Cairngorm in the work place: A trilogoy – in four parts… Read the rest of this entry »

A general introduction: The Session Facade enterprise design pattern allows you to create a clean, well-defined interface to complex and/or composited business objects. The Service Locator is an object that gives you a one-stop shop for all your service needs. It holds a reference to all of your services whether they are Remoting, web services, http service calls or other external resources. The Business Delegate is a layer of separation between the Service Locator and the control (command) code, which is very helpful in Flex as it’s an excellent place to setup your responders to the asynchronous calls that you will make and handle service problems.

Facades

The Facade pattern is widely used and usually without notice… Read the rest of this entry »

Some say that Flex, due to it’s natural separation of interface and server, gives you the freedom from the tedium of working with MVC. Well, ok, I have an opinion on that like everything else…

Flex is awesome, and it does many things, but facilitating laziness is only a superficial benefit. Sure you may start building Flex apps with little to no design pattern influence and you may design a complex Flex application that is so removed from the server-side logic that you feel justified in your decision to use “the quicker, the better coding”. I have done this myself. But all of the original rules apply (but with built-in benefits). Read the rest of this entry »

:: guest.booq 1.5 ::

September 20, 2007

:: guest.booq 1.5 :: With a lot more meat to it, here is the next iteration in the guest.booq series. I will be blogging about the methodology as time permits… hopefully someone enjoys.

:: guest.booq ::

September 16, 2007

Ok, so I’m just spicing up a lame name with punctuation (that’s always a bad sign) but I wanted a little more then a hello world type application.

: guest.booq : here it is. This is about the most simple application using Cairngorm you will probably find. There are no fancy effects or transitions and the form isn’t saving to the database yet, but I wanted to get a simple listing/drill-down project up for preview. In the coming days I’m going to add functionality to this same interface to show you how easy it is to extend and alter with Flex and ColdFusion.

Some things to note: The View is being controlled by a ViewModel and the fields are bound to data model objects in the ModelLocator (another solid denterprise design pattern) . The Services are registered as RemoteObjects in the Services.MXML a very clever implementation of the ServiceLocator design pattern offered by Cairngorm.

I hope to get the users editable in a day or so (possibly changing jobs so I’m sorry if it takes longer). Eventually I hope to consume some third-party services, get some Stock Ticking maybe weather, Account management, usage tracking… all kinds of high-hopes for this little jewel!

Servicing so many…

September 14, 2007

ColdFusion CFCs are gods gift to web development. Yes, there are security concerns, but with a good design you have at your disposal a tool for creating an interface, web method, web service, well defined objects and more. I love to create a Service Layer and connect a Flex Application to it because I know how much work I’m not doing.

My service layers are simply interfaces (as I believe most are). No logic really, just a remote interface to the business layer and some security. If I’m writing a external app there are more considerations than an internal. The external remote service calls are wrapped up in a RequestDTO Object of some kind and they payload a security context dto of some kind. In this case the Service Layer will be breaking up the composite DTOs and accessing various BI calls to complete a process. This is a pattern called Session Facade and it relies heavily on the choice of DTO design.

If I didn’t explain the importance of DTOs then I should have. A Data Transfer Object (sometimes called ValueObject) is an object defined by its use more then by the pieces of data that make it up. A ShoppingCartDTO will have an array of Items, a user maybe and various other configurations but the shopping cart looks nothing like that in the database (or even the abstraction layer). The Services layer is going to deal with incoming requests, received as DTOs and interact with the BI layer passing along DTOs and getting DTOs back. What is the difference between the DTOs and DAOs? Well with EJBs sometimes there is no difference (not a good design to me). Mostly the difference is in simplifying the object to work for the UI and the services layer without carrying around anymore information then necessary. A DTO also gives you the opportunity to composite DTOs and configuration properties to transfer a complex set of objects as a single object. Another handy function: it gives Flex (a separate technology from ColdFusion and Java) the ability to use native ActionScript objects as proxies for middleware objects in both directions.

With these DTOs available to Flex as objects, and not just graphs of simple properties – very strict definitions can be written on the Flex side. This fits in very nicely with an MVC framework like Cairngorm. With well defined objects, views can be bound to DTOs instead of having to muddy the waters with hundreds of listeners.

more on a later date (hopefully with examples)…

When will I ever get to Flex?

September 1, 2007

I’m working on it… I want to cover these other important issues about application development before I drop the bomb. And it is… The Bomb…