Questions and Answers from my EasyMVC eSeminar yesterday
October 17th, 2007
If you attended my eSeminar yesterday and I didn’t get a chance to answer your question, see below. Click the “read the rest of this entry” link below for more.Q: Why did you make the ChatModel constructor public instead of private?A: ActionScript 3 doesn’t support private constructors, so if you’re trying to create a Singleton, you need to throw an error in your constructor if an instance has already been created.Q: have you looked into using a singleton to dispatch events? I use one I found on the net that allows dispathc at any level to any level…. Similar to CairngormA: Earlier versions of Cairngorm used to bubble events all the way up to the controller. There are a few rare cases where that isn’t ideal. In order to participate in event bubbling, an object must be part of the DisplayObject hierarchy, so if you have some object that isn’t on the displayList, it can’t bubble up an event. However, that’s typically not an issue for most apps. Also, if you have a very deeply nested component that needs to dispatch an event and for performance reasons you need to handle it immediately, a Singleton EventDispatcher may be in order. Again, these two cases are rare in my opinion, so I use bubbling for simplicity’s sake.Also, even if you’re using CairngormEventDispatcher, you will likely want your events to bubble up at least a level or two and then be dispatched using the CairngormEventDispatcher by a more senior view.Q: Where would you handle Remote Services like AMFPHP in this framework?A: I put those in my controller class for small applications. For example, let’s say my component dispatches a LoginEvent that bubbles up to the controller. I would handle it in my handle_loginEvent method where I would create the HTTPService or RemoteObject and consume the service there. If your controller class starts growing out of control, I would borrow the Business Delegate approach from Cairngorm. In other words, put the code that calls your service into a separate class. You could then instantiate that delegate from the EasyMVC controller.On a related note, Cairngorm uses Command classes to encapsulate event handler code. The EasyMVC controller keeps things simple by having all of its event handlers in one class, but if you want to start cleaning up your controller, you can implement the Command pattern without technically using Cairngorm. You would still have event handlers in your EasyMVC controller, but inside those methods you would instantiate different Commands to do the work. This approach is more flexible than the FrontController used in Cairngorm which is just a dispatcher and it doesn’t let you associate more than one Command per event name. In the EasyMVC controller you would manually instantiate those commands, so you could have more than one per event and you could set up a sequence of commands manually.Q: Is it advisable to use Flex to create the entire website or it should be used for just widgets within a website?A: For websites, I would usually avoid using Flex for the whole thing. I’ve tried it both ways and I prefer using Flex for widgets that add functionality to my site. Search engine optimization and the ability to change text with a text editor are my main considerations.Q: why use getInstance() instead of a static getter (and how does the difference relate to data binding)?A: Using public static function get instance() would probably work just fine. Binding should work the same either way. Since Java doesn’t do getters like that, and Cairngorm was created by Java guys, and EasyMVC is derived from Cairngorm, my habit is to use getInstance() instead.Q: where is this Caringon info and source located?A: http://labs.adobe.com/wiki/index.php/CairngormQ: Would you suggest someone start here instead of trying to learn Cairngorm right off the bat?A: Absolutely, yes. Cairngorm is overkill for most projects and I certainly wouldn’t recommend it for your first project.Q: Is there an easymvcflex.com website / link ?A: Be sure to subscribe to this blog for more information about EasyMVC. I’ll be posting more information soon.Q: How does the architecture you’ve demo’d effect UI desingers who are not allowed to touch anything beyond wizards and MXML? It seems that going with this model, although it looks clean complicates the separation of code and UI.A: This approach, like Cairngorm, is designed to separate business logic from your views. In other words, the components that the UI people need to touch don’t have much code in them — just enough to dispatch events and listen for changes in the model. Plus, this approach allows you to move those components around your application without breaking anything. That’s key for the UI designers to be able to layout the components any way they see fit.Q: Tom… How long was your learning curve for Flex? A: Learning the basics of Flex is very easy. Learning how to architect a Flex app cleanly takes some time. Hopefully I can help shorten that part of the learning curve for others.Q. how about modules stand point? would I get this architecture per modules???A. The answer to that one deserves it’s own post. Stay tuned.Q. Why would you use Cairngorm?A: I probably wouldn’t use it again, personally. I think it only makes sense for very large applications that have a large team of developers working on different pieces.Q. good books on Flex MVC?A. Not that I know of.Q. Is the EasyMVC simply the sum of what was demonstrated today, or is this a library of components.A. It’s the sum of what was demonstrated. There is no library of code to include in your project.Q. Regarding the controllers, currently you have the chatController. Should all controls be placed in this one file for the chat program. Or is it better to divide them into different files for different activities.A. For something like a simple chat widget, you should use just one controller for your event handlers.Q: How would this application have been done different in cairngorm?A: Events wouldn’t bubble all the way to the controller. Instead, you would use CairngormEventDispatcher.getInstance().dispatchEvent(). The controller would just map events to Commands. A Command is basically a class that encapsulates an event handler. The Singleton model that I created is identical to the ModelLocator in Cairngorm.Q: Is the source availible? To go over it on our own?A. EasyMVCQ: which keyboard shortcuts to do you use constantly (e.g. Ctrl+Space, etc.)A: Ctrl+Space will auto-complete and auto-import. I hold down Ctrl and click on references to jump to where they were declared, etc.. I hold down Ctrl+Alt (Cmd+option) + down arrow to duplicate a line. I hold down alt/option and use the up and down arrow keys to move lines.Q: How was it that Tom was able to get the import statement in without typing?A: Always use auto-complete (Ctrl+Space) and your import statements will be automatically added also.Q: would you continue to use Flash IDE once you acquire Flex Builder, or do you just use Flex builder for everything?A: I only use the Flash IDE for creating assets, embedding fonts, and anything that needs a timeline-based animation. Everything else I do in FlexBuilder.Q. Is it easier to drag and drop or to know and command MXML directlyA. I never use design view. I think it’s easier — it’s certainly easier to be precise.Q: Do you prefer the SA version or Plugin of FB?I use the standalone version of FlexBuilder because I’m not a Java developer. If you’re a Java developer and you’re already using Eclipse, just add the FB plugin. Otherwise, I would just stick with the SA version.

October 18th, 2007 at 4:45 am
For those of you that missed Tom’s presentation, I have written an article on it here http://www.clockobj.co.uk/2007/10/17/simplified-cairngorm-easy-mvc-for-adobe-flex
Regards,
Jon
October 18th, 2007 at 8:10 am
Thanks for the Q&A and Jon’s article is also great.
October 31st, 2007 at 10:23 am
[...] A transcript of the questions and answers session from Tom’s eSemminar, is also available on his b… [...]
January 10th, 2008 at 10:25 am
http://themadadmin.com/wp/?p=1070
Sample application using Flex, EasyMVC, AMFPHP, PHP, MySQL.
June 22nd, 2009 at 2:58 pm
Another reason to use getInstance() over a static getter instance property is that getInstance() allows you to pass in variables where a getter does not. This makes it extremely easy to turn a Singleton into a Multiton without doing as much refactoring.