The code is absolutely beautiful in both utilities and they both offer some interesting benefits but there is a more direct, a faster, and an easier way that compresses the job of module-to-module, module-to-shell, and shell-to-module communication into a single method. Its so simple, I am convinced that I am missing something but I just don't see it. Can someone help?
Here is the method and it can be placed on any subclass of the Facade that wishes to perform module to module communication:
public function broadcast(name : String, body : Object = null, type : String = null, destinations : Array = null) : void
{
// Assume all modules will receive the notification, even the calling Facade instance.
if (!destinations)
{
for (var key : String in instanceMap)
Facade(instanceMap[key]).sendNotification(name, body, type);
}
else
{
while(destinations.length)
{
try
{
Facade(instanceMap[destinations.pop()]).sendNotification(name, body, type);
}
catch(e : ReferenceError){}
}
}
}
All this does is take an array of keys that were assigned to the Facade instances on creation and matches them in the instanceMap to route notifications. All you have to do is call braodcast() (Global) instead of sendNotification() (Local) when you want to notify other modules. Targeting occurs by passing the array of keys to the method. Since the static instanceMap already contains the instances of any and all Facade objects created within the application (provided the getInstance() factory method is used), it seems silly to do it any other way...unless of course I am missing something.
Justin