I wrote a popular MVC framework for ColdFusion. I ported it to Flex. I've done large-scale Cairngorm projects, and been involved in PureMVC and Mate tasks. The short of it all is that, for me, Swiz just owns the competition and any other MVC framework I've used in any environment. If I wrote a new MVC framework for ColdFusion, it'd look like Swiz.
It does so for a very simple reason: it's so simple that it's almost an anti-framework. With the release of 0.6, it's possible to write a well-architected, notification-driven MVC RIA where (get this!) - none of your source code knows anything about Swiz. Seriously. There's no framework-linked IValueObject() that does absolutely nothing, no event maps to write, no framework-required listNotifications(). Heck, I think my last Swiz app didn't even import any classes from the framework except for the <swiz:SwizConfig> tag in its main application file.
Heresey you say? A Flex framework without boilerplate? No explosion of little procedural scripts hiding under impressively named Command pattern variants? How's this? It's all about Dependency Injection, Mediation, and Autowiring. All you have to do is write plain old AS3 classes then sprinkle them with short and sweet Metadata to describe your application's behavior.
Dependency Injection (Beans.mxml)
In your Beans.mxml file, you define dependencies that your application needs: Controllers, RemoteObjects, data models, Consumers, Producers, etc. Think of it as a big configuration file. If you use Spring (or ColdSpring), think of it like applicationContext.xml (Spring) or your ColdSpring.xml file (ColdSpring).
Mediation
In Cairngorm, PureMVC, and all of the others, you have to jump through framework hoops to configure a system of application-level notifications: events that aren't part of the UI hierarchy, such as informing your controller tier of inbound data from a Consumer or a user clicking "Save."
Swiz says "Forget that!" and uses an annotation (which could actually be framework-neutral!). With the addition of UI-hierarchy event mediation (read: Swiz handles bubbled UI events), that makes things ridiculously simple.
In a view:
<mx:Button click="dispatchEvent( new Event('buttonClicked', true ) )" />
In a class named SomeController, which has nothing to do with Swiz and is just a plain AS3 class:
[Mediate( event="buttonClicked" )]
public function tellMeAboutIt() : void
{
Alert.show("Someone clicked a button")
}
Any function on any view or Beans.mxml-registered bean (or any class you manually request wiring) for can use this insanely simple event system. Like WinAMP, it whips the llama's arse.
Autowiring
Ever had fun binding to GiantGlobalVariablesLocator.getInstance().users? Does it make you twitchy just having something like a big glop of global variables attached to a ModelLocator? Swiz'll help there, too, and you don't need to use any framework classes to get there (or write a pseudo-Singleton implementation).
Going back to our button clicking example, let's pretend the SomeController.tellMeAboutIt() function did "this.buttonClickCount++", and that SomeController was registered in Beans.mxml and was bindable. In any view, I can just do:
[Autowire( bean="someController") ]
public var someController : SomeController
Then, if I want to show click count:
<mx:Label text="Clicks: { someController.buttonClickCount }" />
Swiz'll go ahead and set the "someController" property automagically, and it'll just work.
Now, this does imply that the view knows about the API of the Controller, which is OK in MVC. We can, however, decouple this (to keep the PureMVC users happy :) ): just have tellMeAboutIt() dispatch a "buttonClickCountChanged" event that contains the new button click count. A mediated function in the view (or a presentation model for the view, if that's your cup of tea) can listen for "buttonClickCountChanged" and update its state from the event's payload. Yeeeeha! View :: Controller decoupling with nothing but annotations!
Conclusion
Swiz takes about 30 minutes to learn. 15 if you know Spring or ColdSpring. It provides all of the architectural decouplings of its competitors, but you only need to learn two annotations rather than a framework's API. It's a no-brainer.
Learn more about swiz at http://swizframework.org, or check out Brian Kotek's series on it at http://www.briankotek.com/blog/index.cfm/Swiz .
Comment 1 written by Ben Clinkinbeard on 9 July 2009, at 1:59 PM
[Autowire( bean="someController", property="buttonClickCount" ) ]
public var clickCount : int;
...
The knowledge of your controller's API is now encapsulated in the metadata, meaning Swiz knows about it but your code doesn't.
Thanks again for the great post. Swiz FTW!
Comment 2 written by Chris H on 9 July 2009, at 3:44 PM
Comment 3 written by David R on 9 July 2009, at 6:54 PM
Comment 4 written by Ben Clinkinbeard on 9 July 2009, at 11:20 PM
Swiz has also been used on plenty of large commercial projects already, so its not unproven in that sense.
I would encourage you to check out the Google group if you're interested in learning more.
Comment 5 written by Cliff Meyers on 10 July 2009, at 11:51 AM
Comment 6 written by Jeffry Houser on 10 July 2009, at 3:05 PM
"Now, this does imply that the view knows about the API of the Controller, which is OK in MVC. "
Strikes me as wrong. The purpose of MVC is to separate and encapsulate view and model code. The controller is supposed to tie everything together to form the application.
If the view has ties into the controller, that breaks encapsulation and makes the view less reusable.
Am I taking this comment out of context? Or am I wrong?
Comment 7 written by dcolumbus on 10 July 2009, at 3:18 PM
I've been developing in Flex for a few years now. I've taught myself everything I know with the help of Google, naturally. I installed Flex, read the given help files and since I came from Flash, I made a bit of sense of it all and began programming RIA's.
It's only recently that "frameworks" even came into my vocabulary. I understand that they organize your projects and help intercommunication within your application. But I find frameworks to be alien language and unnatural. I honestly don't even completely get their worth... where you guys say "ah, that's wonderful! but have you ever thought about [this]?" I scratch my head and have no idea what the heck anyone is talking about.
That being said, I looked into what seems to be the biggest and most widely used framework - Cairngorm. I don't get it. I've gone through a few tutorials - videos and written - and honestly get more and more confused every day. Then I found Mate and noticed that it was so simple in comparison and noted that it was extremely flexible when it comes to reusable code from component to component. Things started to make a little (and I do really mean little) sense.
So the real question is: am I wasting my time inquiring about frameworks? What's the point and why do I feel that Swiz is just another "my Dad can beat up your Dad" example?
Comment 8 written by Jamie Krug on 10 July 2009, at 3:36 PM
@dcolumbus: I'd certainly recommend giving Swiz a fair shake, for reasons above and then some. The autowiring is super helpful in any OO world, and Swiz makes it dead simple -- meta-driven. As Joe mentions, Swiz in general is incredibly loosely coupled in your code -- nearly non-existent! You needn't extend custom base classes from the framework, like many others require.
Swiz manages to give you the both of best worlds -- a framework to speed and ease development, scalability and maintainability, while remaining very lightweight, loosely coupled and a tiny learning curve. That is, IMO anyhow :)
Comment 9 written by Jeffry Houser on 10 July 2009, at 5:23 PM
If a framework doesn't do these things for you, don't use them. I've met plenty of people who debate whether frameworks are good or bad. In many cases, good or bad really depends on the problem you are trying to solve.
Comment 10 written by dcolumbus on 10 July 2009, at 8:57 PM
Comment 11 written by Ben Clinkinbeard on 10 July 2009, at 9:35 PM
Swiz is less prescriptive than a lot of other frameworks. Cairngorm and PureMVC, for example, encourage a specific folder structure for your projects, and a consistent methodology for implementing features. In Cairngorm its (roughly) create an event class and corresponding command class, map them together in the FrontController, and trigger the command by dispatching the event. This more prescriptive approach can be helpful for coordinating large development teams because the framework has specific guidelines for where to put certain kinds of code.
Swiz is more like a collection of utilities that enable/help you to create better applications, and to do so quickly. It provides mechanisms for dependency injection ([Autowire]), event handling without directly coupled components ([Mediate]) and some convenience methods for calling remote services, chaining remote calls, etc.
Frameworks are certainly not for everyone, and not for anyone in every single scenario, but hopefully this explains some of the potential benefits. If you have further questions about Swiz be sure to check out the Google Group at http://groups.google.com/group/swiz-framework
@Joe Sorry for writing novels in your comments! :)
Comment 12 written by Sean Hess on 12 July 2009, at 5:08 PM
To qualify for "2nd-gen" status, you have to have dependency injection and handle bubbling events. Autowiring vs Mapping is just a preference. Personally, I find it extremely orienting to have one class (the map) that handles the coupling, and let my controllers and views know nothing (including their metadata) about the rest of the system. Thus, I lean towards Mate.
I this Swiz is a fine framework, and if you get a bigger endorphin rush writing AS and Metadata than MXML, it's the right one for you. Otherwise, choose Mate.
Comment 13 written by ryan on 15 July 2009, at 5:07 PM
the biggest mistake you could make is if you feel the need to use a framework simply because people are talking about it...
if you don't feel the need then don't use it... but do take the time to learn about it and at least give yourself a sample application project in at least a few different frameworks...
check out tony's 6 framework quest series: http://www.insideria.com/2008/12/frameworkquest-20...
Comment 14 written by ryan on 15 July 2009, at 5:11 PM
i've been hacking away at a mate application and while i like the refreshing thought process compared to cairngorm i gotta be honest and say that i really hate coding my controller in xml...
its just not my preference...
[Add Comment] [Subscribe to Comments]