Flex Pasta » Introducing The Penne Framework for Flex 3
Introducing The Penne Framework for Flex 3
As first discussed in a previous post, “The Pros and Cons of Cairngorm“, I noted the need for a more lightweight framework for developing in Flex and Air. I am releasing version 1.0 of The Penne Framework, a simplified Flex and Air framework, as a second option to the popular Cairngorm Framework. This page has the Penne base code, and a java/flex example application using Penne(called the Italian Store) with remote objects. I have created a diagram which summarizes how Penne differs from Cairngorm.
About the Diagram
Let’s discuss the command class in Cairngorm, because this is the meat of the difference between Cairngorm and Penne. In Cairngorm, I will have one command class for a type of event. For example, I might have a remote service that returns a list of customers. This would have one command class. Then I could have another command class for getting all of the customer orders. In Penne, there is one request and result class for both of these remote calls. The request would have 2 methods in this case:
1: getAllCustomers(),
2: getAllCustomerOrders().
The result class would have
1: getAllCustomers(custList:ArrayCollection),
2: getAllCustomerOrders(orderList:ArrayCollection).
In a large project, the number of classes to create in Cairngorm would be drastically higher than Penne. There is a ton of overhead work to create in even a simple remote call in Cairngorm. With Penne, it is easy to grow your project without as much busy work.
Penne still keeps a strong structure for code layout. It is easier for a developer to see what is happening. Instead of looking at an event that is mapped to a command, which is mapped to a delegate, which calls an external service, in Penne I just call the method directly from a view class. It is very clear the remote service I am calling and from where. If I use BlazeDS and remote objects, my java remote methods can directly matchup to my flex request/response classes. There is a huge reduction in steps to figure out a path to a bug with Penne.
Hang on a Minute, How can Penne just delete all those event classes?? How will Penne ever have code reuse??
Penne is not getting rid of event classes. They are just not part of the framework. I am no longer required to create one for every type of remote service call. If creating a component such as a date chooser, or datagrid, then standard events are used to allow parent components to interact with them. Depending on the task, this kind of flexibility in a component is usually NOT needed. With Penne, call the request method directly from within a view component, and the result will cause bindings to fire changes back to the view components. Only use events for remote service calls when it is required for code reuse or the parent component needs to be aware, not for any other reason. I don’t create events because I have to anymore, I create them because they are NEEDED for something more than just kicking off a remote service call.
What about the model? Certainly Penne can’t get rid of that too?!?!
The model isn’t gone in Penne. Model variables still exist in the application. ModelLocators still exist just like in Cairngorm. Penne, however, offers a secondary option for remote services. Penne allows the developer to place “model” variables inside the response classes if desired. By placing the result directly in a variable in the same class, tt becomes much easier to see what binded variable goes with which remote service call. In my view layer I can just say PastaRemoteResult.getInstance.pastaTypes. In Cairngorm, if you opened up a model class and I said to someone, “Where does this model variable customerList get set?” They would probably start sweating and begin opening up all of the command classes trying to remember which one(s) it is. Then after it’s found a text search will be done to find the corresponding view where the CairngormEvent that goes with that command gets invoked. It is tough enough for the person who wrote the code to know where everything lives. Just wait until a new hire comes to code on the application has no idea what is going where. With Penne it is simple and structured. Everything is easy to find. If for some reason I need to control things like viewstacks and state management, I can still create a separate “model” class just for this, but all remote service calls’ model variables live in the response class.
Conclusion
The Penne Framework improves upon Cairngorm by simplifying it without sacrificing separation of duties. Penne drastically reduces the number of classes created in a large enterprise project. This reduces code complexity and readability. As an added benefit, Penne will reduce my pesky Flex Builder compile times!
Take a look at Penne, I welcome feedback and suggestions. The Design approach to flex can be improved. I hope Penne can start to accomplish this goal!
The Code
Here are the three zip files to download. One is the Penne.zip which includes the Penne source and Penne.swc. The other two are the Italian store. There are 3 projects in all which can be imported right into eclipse. I am using flex 3, java 1.5, with eclipse europa. The example Italian Store application is extremely simple. It shows how Penne can be used and offers comments as to how Penne works.

13 Comments
1. Reji replies at 17th May 2008, 5:48 am :
Hi,
1. in PastaRemoteRequest.as -> updatePastaType, instead of service.getPastaTypes(); it should call service.updatePastaType(), right?
2. in PastaRemoteResult -> getPastaTypes(ac:ArrayCollection):void, instead of PastaRemoteResult.getInstance().pastaTypes = ac;
it can call pastaTypes = ac ; ,right?
3. As in Cairngorm Model Locator, where do we keep the data which’s to be available in other screens/classes? in PastaRemoteResult itself?
4. Any examples showing multi screen/alternate flow use cases are availabe?
5. Any forum for penne?
Regs,
Reji
2. Brian Telintelo replies at 17th May 2008, 10:00 pm :
1. Fixed.
2. Good catch, the code will work but you are right, it will already be the same instance of the result.
3. The ModelLocator from Cairngorm does move to the PastaRemoteResult, the reason being is it would be easier to see what data went with which rpc calls. I’m not sure if I like this as their may be variables you want on the model but don’t use remote calls. Your thoughts on this?
4. Not yet, but good idea.
5. Only this post right now.
3. Dimitar G. replies at 14th July 2008, 10:08 pm :
Any chance to post a comparison against PureMVC AS 3 Standard framework or its bigger brother MultiCore?
4. Brian Telintelo replies at 17th July 2008, 8:44 pm :
I have not worked with PureMVC, but did look at it. I have had several people ask me about that so maybe I will look at it and get back to you. Thanks for the comment.
5. Guest replies at 18th July 2008, 11:13 pm :
Don’t take this constructive criticism below personally.
Please stop it with the silly naming conventions. “getPastaTypes()”? “updatePastaType()”? You guys are killing me! Ever since Java started this assinine trend with “JavaBeans” (or even the name Java itself) it has been nothing but painfully cheesy and irrelevant word play in the whole software industry, obfuscating what the real purpose of these things are. ARgh!
Look up a book called Code Complete; things (functions, variables, etc) should have meaningful, self-descriptive names that convey useful information. It’s fine for the name of an architecture or whatever, but it shouldn’t go deeper or we risk giving things meaningless names. (Penne seems like more of an architecture like Cairngorm rather than a framework btw.)
Looking at that code above someone has no idea what “getPastaType” or “updatePastaType” is even supposed to do. Is it a model or remote object? Should PastaRemoteResult at least be PenneRemoteResult? Probably… even plain RemoteResult seems better, if only because it’s shorter yet just as meaningful.
I’ll try using this architecture once the naming conventions are improved, but probably never otherwise.
6. Guest replies at 18th July 2008, 11:25 pm :
Of course this last lecture may have been pointless, as it appears this code came from the examples and not the architecture code. =/ Points are still valid though. :p
7. Nobody replies at 20th July 2008, 3:36 pm :
You should make an interactive “explorer” diagram like cairngorm has, to visualize how this works. It would make learning it MUCH easier.
http://www.cairngormdocs.org/tools/CairngormDiagramExplorer.swf
8. Nobody replies at 20th July 2008, 4:44 pm :
You may want to think about how you’d use a messaging service in Penne as well, I don’t think Cairngorm can really handle that type of service so it would be a step up.
9. Brian Telintelo replies at 20th July 2008, 7:45 pm :
- Good suggestion in regards to creating a diagram!
- The name may be cheesy, but if you go to apache.org you will see a whole lot of projects with so called cheesy names, such as ant, forrest, gump, beehive, cocoon, harmony, jackrabbit, shale, maven, james, and lenya among others. Cairngorm is named after a mountain range, and I decided to call it Penne, rather than the “Rocky” Framework:)
10. Nobody replies at 27th July 2008, 10:43 pm :
Well, you’re certainly not to blame for the cheesy naming standards.. an some of those are pretty bad. Cairngorm isn’t cheesy but I don’t think anyone knows how to say it. lol
Would love to see a Penne Diagram though. That’s how I learned Cairngorm so easily, just by following that swf and clicking on the objects to see the code behind the pictures.
11. Nobody replies at 27th July 2008, 10:49 pm :
But Cairngorm seems so amateurish. The fact that you end up basically copy/pasting half your code (or need a tool to generate it all) makes me feel like a beginning programmer again. Maybe with some things feeling like that is good, but not for this! Speaking of “Code Complete”, it makes Cairngorm look pretty ugly.
12. fabian replies at 1st October 2008, 3:38 pm :
i’m new to flex and i haven’t looked at Cairngorm but i’ve read stuff about it which never looked very promising for real world stuff. yours looks much easier but still:
call me stupid or not but why does every one love to make tousand of interfaces?
why do you need IPastaRemoteRq.as and IPastaRemoteRs.as?
will there ever be another implementation?
i think it’s good to have interfaces in penne but in the store application i would keep it as simple as possible.
are you using this in a fairly big application?
fabian
13. Mohammed Khan replies at 10th November 2008, 12:24 pm :
Hi
I have recently evaluated the penne framework for my ongoing project, and i believe it really makes life a bit easy because i still miss the ModelLocator instance. Kindly correct me if i am wrong at it. Also i have posted my experience with penne here http://tinyurl.com/668bum . Feel free to comment.
Leave a comment