Cairngorm – an explanation
Ok guys I am going to spell this one out as purely and simply as I can to dispel any previously mentioned mystique surrounding the fabled framework.
Okay to start, Cairngorm is based on the MVC collection of design patterns. This is Model, View, Controller layers that are all distinct and seperate from each other.
The idea is that the user interacts with the view, the view sets off events relating to user input, the controller element of the application handles the event and calls whichever service or command required and the data model is then updated from the service. The view is bound to the data model and so visually updates when the model updates.
The controller handles all of the business logic. Cairngorm uses a FrontController for listening to events and and matching them with commands. The Commands are also part of the controller layer and these have a built in method called execute() which fires as soon as the event is heard. this is where you want to do your service call and add your event listeners for Result and Fault! The handlers are also written within the command class.
Once you get your result then normally you would update your model from the result handler by possibly calling another command which handles client side commands like updating a shopping cart array on the model because you know it has been saved in the database successfully. As the shopping cart view component is bound to the models shopping cart arrayCollection it updates its view with the extra item giving the user visual confirmation of their action.
So you have two singletons. One is a bindable data class (ModelLocator) and the other defines your services(ServiceLocator) without result or fault handlers. These go into your command classes allowing you to use bespoke handlers for each command whilst at the same time allowing various commands to access the same service. This is a big advantage!
Your command normally references both of these singletons because a) it calls the service and b) it handles the service result by updating the model!
I hope that is clear, it is a basic implementation of Cairngorm and you tie it up generally by using Cairngorm events, but hey its late and I am off…
Design Patterns and OOP
Do Design patterns and OOP go hand in hand? They bloody better or something is going very wrong indeed. There always seems to be exceptions to the rule in programming. No sooner do you make a bold statement than someone pipes up with the scenario that undermines your certainty. I am guessing that an exception to the rule on this occasion would be design patterns somehow being used in procedural programming like splitting certain types of functionality into different areas. Apart from that though lets assume we are talking OOP and in particular Actionscript.
We generally build web apps with actionscript but now we can also build desktop apps with Air. There have been 3rd party ’swf to exe’ platforms out there for some time already but with Actionscript 3 and the extendable frameworks it provides we are in a very powerful place these days.
I am writing an Air application at present for a client and I have yet to call any real services. i have been reading and writing objects to the file system. Air has methods that serializes and de-serializes the objects you create. I have also been connecting to SQL lite and using event model to create Cairngorm-esque frameworks. This brings me onto Cairngorm and design patterns as really you should use services for any external data even if it is local.
Cairngorm is a word, a scottish mountain range, but still just a word. I used Cairngorm for the first time in 2007 within a team of flex developers and to be honest the whole approach from the team was that of fear. With bosses looking over shoulders and team leaders under pressure we dived into cairngorm taking the lead from the lead. You do this and we then do that and this is the view1_controller and this is the view2_controller. Wow, a lot of classes started to be written, code was probably being duplicated and all we really needed was an unhurried discussion, with documentation and framework diagram in hand at the project outset. Within a couple of hours everyone would have been on board. Instead it was an environment of every man for himself, a quiet atmosphere of people concentrating (or suffering in silence?).
The result – refactoring of lots of code costing lots of time later down the line, some of the team being let go and slight animosity to the only remaining contractor (no guesses for who that was).
The point is though, there is a lot of mystique surrounding design patterns and frameworks (that act as collections of design patterns). This mystique is unfounded and unneccessary and instead of jumping knee deep into coding as soon as you get the go ahead for the project, give some thought to the patterns and why they are there. They are there to simplify your job not do the opposite and this is precisely what seems to happen everywhere because devs and team leaders are not given the quiet time to simply read, comprehend and discuss exactly what the framework or pattern does and so the project starts with confusion and mystery and ends in a big ball of spaghetti usually…
So to cap it off Cairngorm is actually very good and very simple, just spend a couple of hours reading through docs and examples and you will get it. I will blog next about an overview of what Cairngorm is and how it should be used in its purest form.
What is Flex?
I get asked a lot about the differences between flex and flash, mainly by agencies calling me up looking for a contractor to start asap. Normally far from home at the wrong rates.
Anyway having explained these differences to the layman on numerous occasions I thought it to be an apt subject for my first blog, especially as like them, you dont know what flex is.
Here are some questions I recently answered for an agent. Feel free to put me right if I havent been quite so accurate in anything but remember I am talking to a layman..
What platforms does flex work off? – Published Flex files (swf’s) run in the flash player which, is a browser plugin or can be a standalone app like a projector or .exe(application). This means the flash player is platform independant giving it a good advantage.
What web servers are required? – You do not have to work with any web servers or you can use any one you like. Flex creates client side applications not server side so any server side interaction goes first through a server side language such as php/asp/java.
What database knowledge is required (if any?) – none but as a developer it helps to know some basics of SQL
What frontend languages are you using?- Actionscript3 is the language used to create swf files using flash and flex
What backend languages are you using?- You can use any back end language, this depends on the server environment wheteher you use java/php or asp.net, etc
What design patterns do you use? I use MVC… a collection of design patterns seperating the model, view and controller layers. This incorporates other patterns such as value object and singleton.
Why do companies use flex and what are the benefits? – The benefits are huge as it is platform independant and doesnt rely on a type of browser just as long as the flash player is installed. The player is installed on a very high number of browsers, in the late 90’s percent, check adobe site for detail. Other benefits are a strongly typed Object oriented language with an extensive framework of classes and components allowing rich internet applications to be built rapidly and robustly.
What are the differences between the flex versions, how is flex 4 different from the other versions? Flex 4 will be named Flash Builder apparently and I know this will cause confusion with the agencies just getting to grips with flex/flash differences. Flex is an IDE an interface for programmers to work inside to develop actionscript applications using the flex framework(a collection of prebuilt components and classes). The difference will be improved interface and extended framework of classes. Any updated versions have some changes but fundamentally it will be very similar to previous versions.
What are the alterrnatives to flex? Alternatives to flex are mainly AJAX and Silverlight, flash is an alternative as a development environment but essentially is till using actionscript.
What is the future for flex? who knows? At the moment it is the market leader in developing RIA’s but with HTML5 being released and silverlight nipping the heels of adobe flash technologies you just cant tell. The developer base in RIAs lies with adobe.
Interesting answering these questions as it makes you question yourself and helps solidify your knowledge.
Hello Flex world!
Most people probably delete the first wordpress post, the default hello world one, but I decided to keep it as it really was Hello World this time so hello to the world of flex!
Recently set up some new webspace which I am very happy with indeed. I will provide a shameless affiliate link soon and will probably even write a blog about my very good experience, the oppositie to that I was used to. Unlimited everything for peanuts per month is my idea of a good host. On top of that it didnt take long to install wordpress and get my blog up and running. Some of the blogs here were written months ago but I have migrated from a previous blog to this more secure and I think , stylish looking themed WP blog.
WP is the way, thanks for showing me yours Jaz, I may not seem so interested but I listen to every word!
Here’s looking ahead to an interesting future.
