OReilly PureMVC Book

PureMVC Book



PureMVC on the Web

PureMVC Blog-o-Sphere
PureMVC on LinkedIn
Where Should I Declare Notification Name Constants
Tuesday, 19 August 2008


I want to know where one should declare notification name constants. Should they be declared in Proxies or in ApplicationFacade?
Also, declaring notification constants in my ApplicationFacade will really lengthen up the file. I was thinking of declaring them in a separate file called as ApplicationConstants but is there any other method of keeping the notification names?


The concrete facade for your application (typically called ApplicationFacade) is just a handy place common to all the notification participants, and since it also uses constants for Command / Notification mappings, it is usually a reasonable place, if you don't have many constants defined.

But you have a lot of constants you can just as well put them into a separate file like ApplicationConstants. Keep it at the same level in your hierarchy as your ApplicationFacade. This is particularly useful if the constants are to be shared, as in a library.


The View tier and Controller tier work together to service the unique use cases of a single given application, but you don't want Mediators referring to constants defined on Commands or visa-versa, otherwise they'd be in the same tier. So a common, neutral place like the ApplicationFacade or an ApplicationConstants file allows the two to work together without forming dependencies on each other.


And since an application's unique View and Controller tiers are almost always meant to allow you to interact with a specific Model, is perfectly fine for both Commands and Mediators to be mapped to Notification constants defined in the Model tier (typically in Proxies or ModelConstants classes), and to retrieve and interact with the Proxies directly. 


However, the Model should be the most isolated tier, able to be moved in its entirety to another application (perhaps the AIR version of a Flex app) with completely different use cases and UI (View/Controller tiers).


Therefore, the Model tier (Proxies) should not reference anything specific to your Controller/View tiers or your ApplicationFacade/ApplicationConstants.


You should have the Model define its own constants for the Notifications it sends. This makes the Model tier portable. This is also why Proxies cant receive Notifications - you might be tempted to make them listen for Notifications that are defined elsewhere in the application, thus forming an undesirable Model dependency on the View/Controller tiers.
Furl it!
Copyright (c) 2006-2012 Futurescale, Inc.