views:

93

answers:

4

I'm going to write an application with the Air/Flex-Framework. I'm looking for Best Practise and general Design Patterns for designing software especially in Air/Flex. I have experience with this framework but never had the pleasure to write a piece of software from scratch.

For instance:

  • I stumbled across lots of software written in Air/Flex with nearly infinity global vars :-)
  • Most of the software I saw was not object-oriented
  • How can I pack the asynchronous method calls nicely?

I'm familiar with general design patterns by gamma. I'm looking more for advise in designing good quality software with Adobe Air/Flex.

A: 

As with all "Best practices" and "Design Patterns" it depends what you want to do. Every choice you make has trade offs. It is good to understand those trade offs and make the decision to act accordingly with what you need to develop.

Your question is so open ended; I might be able to write a book without answering.

A few thoughts on your bullet points:

I stumbled across lots of software written in Air/Flex with nearly infinity global vars :-)

This is a common approach when using the Cairngorm framework which makes use of a ModelLocator. In many apps the ModelLocator turns into one big global Value Object used everywhere in the app. I talk about how I deal with this blog post: http://www.jeffryhouser.com/index.cfm/2008/3/27/Learning-Cairngorm-Part-6-Dealing-with-the-Singleton

Most of the software I saw was not object-oriented

Despite all the interest about Object Oriented programming, I've never seen any project architecture take a Object Oriented Approach, academically speaking. At best I would call all development a hybrid between Object Oriented concepts and procedural concepts. Many folks I've spoken to seem to claim that any use of encapsulation is OO; while not using encapsulation is procedural. That is, of course, ridiculous

When building Flex Components, you'll be writing a lot of code in the Flex Component LifeCycle methods (createChildren(), commitProperties(), measure(), and updateDisplayList() ); but you probably won't be creating your own object orient architecture.

How can I pack the asynchronous method calls nicely?

I'm not sure what you mean by pack in this context.

www.Flextras.com
A: 

I can highly, highly recommend using the Swiz framework within Flex (I've never used Air but should be the same). I recently had the pleasure in my new job of taking a Flex application my predecessor had built from the ground up and starting from scratch, using any approach I liked.

I wanted to use a framework within Flex, so I had a look at Cairngorm and Mate, but Swiz stood out for its simplicity. You can read it all in the shiny new wiki, but Swiz follows the dependency injection/inversion of control approach of various other frameworks (it's quite similar to Spring if you're familiar with that), but tries to do so in the most hands-off way possible. Simply sprinkle some metadata through your code, and you can get all the benefits with almost no references to the library, and with nearly zero lines of boilerplate code (in stark contrast to Cairngorm).

From there, the recommended approach is the Presentation Model pattern (see Best Practices in the wiki) to separate your view from your underlying data (MVC approach), and it works very nicely as well. Swiz is lovely because it doesn't enforce any design choices on you, it simply provides the tools that let you design the way you want. You can "pack" your async service calls with a simple call to executeServiceCall(), passing an AsyncToken, result handler, and fault handler, AND you can pass an arbitrary array of object to maintain references/state between the request and the result. It really is "brutally simple".

The developers on the mailing list are extremely helpful too, and will usually reply within the day. I can't thank them enough :).

Pie21
+1  A: 

Have a look at RobotLegs. It includes dependency injection is very flexible, easy to get up and running pretty quickly.

http://www.robotlegs.org/

There are many, many frameworks for Flex. Its quite a chore to pick and choose one over the other. Go with something that has lots of examples and good community support.

swidnikk
+1  A: 

ModelLocator is an anti-pattern; I advise avoiding Cairngorm and going with a better framework like Spring Actionscript: http://www.springactionscript.org/

I'd recommend Shashank Tivari's "Advanced Flex" from Friends of Ed for an excellent overview of best practises in Flex. (Apparently, because I'm a new user, I can't post a link, but you can google it easily or find it on Amazon.)

micapam
And I should add, I strongly disagree with the statement above that you probably won't be creating OO software. For non-trivial Flex projects OO techniques are advisable, same with any software development.
micapam