Swiz: Cafe Townsend example (incl. FlexUnit tests)
UPDATE [10/31/10]: Example and its full source has been updated using latest commit of Swiz 1.0 RC2.
Cafe Townsend is a well known application to demonstrate any MVC framework for using Flex or ActionScript. There are already ports of Cairngorm, Mate, PureMVC, Spring ActionScript, RobotLegs and now Swiz.
In cooperation with “my partner in crime” Sönke Rohde we have built a Swiz port including unit tests. Check out the following example and its source.
Live Example
(To view source code just a right mouse click on it)
Source code
You will find the full source of Swiz’ Cafe Townsend example at GitHub.
Thanks!
Thanks again to Sönke for his great cooperation including all helpful tips! Also big thanks to Swiz team for development such a simple to use framework – keep on rocking
-Jens
Thanks, this is great. Swiz 1.0 was badly missing some good examples.
Thanks a lot for providing this example.
Ahhh, I was expecting this to be a swiz 1 example looking at the post date. Sadly it’s not.
I hope someone finds the time to convert these quality examples to the new branch.
Forgive me, I looked at the wrong example (SwizPresentationModelExample) the DemoApp is 1.0
Thanks again!
Using your (great)example I created a Cafe Townsend, now Parsley.
http://separ8.net/separ8posts/2010/cafe_townsend_parsley/cafe_townsend_parsley.html
source:
http://separ8.net/separ8posts/2010/cafe_townsend_parsley/srcview/index.html
Hey Brett, nice Parsley example!
PS: I have not forgotten our chat at FOTB07
OMG, it’s almost 3 years ago now…
-Jens
Cool, me neither
I am thinking of going back this year what about you ?
Jens,
Thanks for the nice sample and upgrade. I took your version(thank you very much) and I enhanced it to create a CafeTownsend Swiz with multi-language features (using l10nInjection); and it also uses the custom LogProcessor metadata processor.
Check out the blog article http://www.gridlinked.info/swiz-localization-l10n-logging/.
Thanks again,
ThomasB
Jens,
I updated my CafeTownsend version (with l10nInjection and Logging) to use your ThunderBolt AS3 classes to log to the Firebug console. I modified your classes with minor tweaks and included those as part of my Swiz fork on GitHub. Swiz, l10nInjection, Logging, and ThunderBolt AS3… what a combo! Love it.
See online sample (and source) at:
http://wiki.github.com/ThomasBurleson/l10nInjection_Samples/sample-applications#demo1
Hey Thomas, that’s awesome! Thanks for sharing this great example and all your Swiz extensions, such as [LogProcessor],
[DeeplinkProcessor]…-Jens
Jens,
Thanks to Sönke and yourself for this great example! I think this is the most commented, best laid out example for 1.0 that I have seen yet.
A few questions:
1) I don’t think I’ve seen the idea of putting the HTTPService declaration in the Beans.mxml file yet. Why did you put it there, and where else could it possibly go?
2) I notice you don’t use Value Objects, but rather an object with some logic. Do you call these Domain Objects? Pros/Cons in comparison to Value Objects?
3) The classes in the model folder (i.e. AppModel, EmployeeModel) are fairly ‘dumb.’ Why don’t you just put those attributes in the presentation models instead?
Thanks!
Mike
@Mike:
1) At the example the HTTPService is used only once to load data of employees and we could declare it within EmployeeDelegate. Anyway, imagine you need to use this service for other calls, e.g. to save any data of an employee using another delegate. Or this service will be changed to a “custom” HTTPService or to a RemoteObject or anything else. The idea behind is to change the service at one place only (Beans), not within all the delegates or anywhere else.
2) As you may know Value Objects are just “data holder” and mostly it be used to transfer data to server side and/or back (@see: Core J2EE Patterns – Transfer Object. You can call it MyValueObject (e.g. EmployeeVO) or just MyObject (Employee). The same thing is happened within the example: Employee.as is acting like a Value Object (holding simple data), but it is not named as VO and it is not be used to transfer data over the wire. It just hold (domain) data as a part of domain models, which can be used everywhere at the application. It can be a selected employee (EmployeeModel -> selectedEmployee) or an employee within the list of all employees (EmployeeModel -> employees) etc. And it if there a need, this “data object” can be hold simple logic (Employee -> fullName)
3) You are right. AppModel and EmployeeModel are just “dumb” models and you could hold this data in PM. But what happens, if you need this data more than once? The idea behind is to store general data in domain models. And if there a need, one or more presentation models (PM) can access to these data. Furthermore, PM could manipulate these data (e.g. sort user by its names) without changing the “original” domain data.
P.S.: I’m glad to hear that you like the example, thanks!
-Jens
@Jens: Thanks for the very thorough response!
Hi,
I’m just getting started in all this, so forgive me if I ask silly questions. I’m doing my best to learn
In the file ErrorUtil.as, the ErrorUtil class is set as final.
Is this done just so it can’t be extended anymore or is there a more specific reason?
Thanks in advance!
JurLan
Jurlan,
using final on classes is more an optimizing thing. If your class will not be used by a subclass to override methods etc., it can be marked final. So the class will be determined at compile time. There is no need to determine it on run-time with an extra cost of CPU.
At Adobe Developer Connection you will find an interesting article about using this “strategy” : “Optimizing content for Apple iOS devices” (Don’t be confused about the “iOS topic” – it is a Flex related article
)
-Jens