This content has been marked as final. Show 4 replies
It is just a pattern / framework. It is not suitable for all applications, no single framework is. Google it if you want to read endless debate. Or dump it if it is not right for you.
I have never used it myself.
Lol, that's the problem. I have to support an existing Cairngorm application of 50,000 lines with 100 events and 400 listeners.'Dumping it' is going to be a huge problem, and should be a warning to anyone else out there. It would be nice if the framework took into account this common pattern, since it seems to be the most common of the frameworks used. And it seems that the framework documentation doesn't make this glaring problem apparent with phrases like 'all events should be Cairngorm events', 'all you data should be in the singleton model locator', etc.
I guess my point is, I think that some of these MVC frameworks need to put in big red letters at the top of their docs: 'DON'T USE THIS FRAMEWORK IF IT IS POSSIBILITY THAT YOU WILL EVER WANT TO USE THIS MUTLIPLE TIMES IN A SINGLE SWF.' Maybe that doesn't happen as much as I think. But I've run across it on 2 projects already (of say 10 I've worked on).
Again, that's unless I am completely missing the big picture and there is some one line fix that solves all of those problems :P Which was my point of posting. Hoping someone knew a quick and dirty way of fixing this.
That said, there is a way around this, which is to use SWFLoader to load the FlexApp and then use SystemManager to get a pointer to the main application so you can call public methods, etc. But this is a maintenence nightmare, as the embedded fonts/style have to then be put into the 'embedder' apps stage, etc., and you lose strict typing and flexibility in general, and it can cause Design Mode to break in Flex Builder.
Yeah, it sounds like Cairngorm may not have been the best choice for the "widgets" you have. I guess you have a point that they should clarify better when you DON'T use Cairngorm. I've never tried to use it when developing a custom component (or anything) if it was going to be added into a full app.
From reading various articles I get the impression (IIRC) that the guys from Farata Systems (might just be Yakov) don't seem to be very keen on frameworks (Cairngorm is called a 'micro-architecture'), but rather focus simply on strong "component design" and using Flex's event system (i.e. dispatchEvent() ). I definitely appreciate that questioning attitude because too often in IT it seems that people just seem to accept "best practices" and "the way it's 'supposed' to be done" as bible regardless of whether it's really adding any value, or adding needless complexity. I think the answer to everything always "depends" and we have to use our common sense and intelligence to figure out whether we're really gaining anything by doing something "standard" that has questionable value.
I've used Cairngorm architecture but not run into your problem, maybe because I only use it at an "Application" level, never ever intending to have the product of that project embedded in anything.
(Haven't read all of this, or I forgot if I did, just putting it here in case something I said about others' opinions wasn't entirely accurate.)
Great article. Thanks for posting it.
Yea, my 'widget' is a video mixer which creates an xml playlist, and the playback component reads in the playlist and plays it back. The code overlap between the two is about 50% as the mixer by its nature contains a player. At the time we were under a serious time crunch (1 month from design to implementation) so some design ideas weren't fully explored, so to speak, and I was just learning Flex at the time.
That said I do feel there is some use for compartmentalized events, just not completley Singleton. I find myself using this.parentApplication a lot of times when I do need a Singleton, though that doesn't work with as3 classes. It would be interesting to see if there was a way to use, say, namespaces to provide this 'singleton-like' compartmentalization for multiple instances. You might be able to set the namespace before starting to manipulate your component, and your events would determine which namespace they were using automatically and create event names based off of that ( "STATUS_<namespace>") automatically.
TIme to go build my own framework! lol