PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: lowpitch on July 29, 2008, 08:55:59



Title: Where to put the various constant names for Notifiers
Post by: lowpitch on July 29, 2008, 08:55:59
Hi there,

After recently getting to grips (http://lowpitch.com/blog/2008/07/21/why-puremvc-and-scaling-the-learning-curve/) with PureMVC and building a couple of test apps, I'm diving in to using it for a larger application. It'll be a Flex app with multiple modules (using Pipes), and I've got the structure worked out quite nicely as I'd like it.

In my test apps, I've tended to create a class which purely exists to define all the Notification name constants, so that any class that needs to send a notification, or react to one, can gather the constant name from this one class. I decided not to put them in the ApplicationFacade to keep that class nice and simple. This has been working pretty well for me, but I'm wondering if it's 'Best Practice'?

Obviously, I'm gonna need one of these constant-storing classes per Module, and the fact that I'm using Modules is really irrelevant to my question. I'm interested to know what people have done when building larger apps with the framework - are you tending to keep everything inside ApplicationFacade? Are you creating a class just to store all the constant names? Are you doing something else which I hadn't considered?

Any info would be much appreciated.
Cheers,
toby


Title: Re: Where to put the various constant names for Notifiers
Post by: andrew on July 29, 2008, 12:05:49
I think this is a good idea generally speaking.  I started to do it this way, but since many of the classes that need to send and receive notifications already had ApplicationFacade imported, I found it a pain to have to add the Notifications import.  This is really just because Flex builder is lame (or maybe I am), and command + shift + o doesn't seem to work (but type ahead with code assist does work).

I have all my notifications starting with a prefix.  Mine is AEV_ for "application event".  This helps with search and replace and finding things.  If you have something like "login" you will find it everywhere.  Again, this is also because the Flex builder sucks for re factoring and misses things all the time. 


Title: Re: Where to put the various constant names for Notifiers
Post by: puremvc on July 29, 2008, 07:52:57
@andrew - organize imports works to remove unneeded imports and to sort the rest, but doesn't add missing ones. For that, place the cursor right after a class or interface name (like Notification or INotification) and press  ctrl space to add the import.

@toby sure put you shared constants in a separate file if you like. The ApplicationFacade is just a handy place within an app.

With MultiCore, if you want to share constants across modules, you can put a constants file into a separate API library project referenced by each module and the main app, so as not to form dependencies between app and module or module and module.

-=Cliff>