Thanks for the reply, Cliff. Your second assumption is correct, there are no notes that all instances will respond to.
However, *currently* the view component instances are created in the mediator's onRegister() method. This is just to defer instantiation and speed up application start time. Please tell me if this violates convention--I've been doing it for some time. Also, the data sets to be used in the application are determined from a separate initial query so the number of View/ControlPanel pairs is dynamic.
//very simplified...
for (var i:int = 0; i < dataConfig.length; i++) {
...
facade.registerMediator(new ViewMediator());
facade.registerMediator(new ControlPanelMediator());
...
}
I *could* modify the application so that it instantiates the view components first, sets the type parameter on them, and then passes them to the mediator constructor during the start-up. It would just be some work changing the current code (but not a problem). However I am a bit reluctant on principle. The type value is of no consequence to the view component. I would essentially be putting it there for the benefit of its mediator which seems... odd. The view component would never actually use the type variable itself.
Anyway, you did make me think of something new with your suggestion. Until now, I have been pretty strict about not modifying the constructor arguments with the framework classes. I guess I thought that was best practice. But if mediator constructor arguments may be arranged, added, deleted, etc. freely, then how about I pass the type argument there directly?
facade.registerMediator(new ViewMediator(dataId));
...
public function ViewMediator(dataId:String)
{
sharedType = dataId;
super(getMediatorName());
}
override public function onRegister():void {
viewComponent = new View();
}
Is there a best practice regarding framework class constructors? Or a convention? There have been times in the past that I wanted to pass parameters to the mediator through a third constructor argument but have not done this because I thought it violated convention (which is to say I haven't seen it done anywhere else). In those instances I have unhappily dispatched notifications to set properties on the mediator. *1
Don't get me wrong, depending on your response, I may still go ahead and just add the type variable to the view components with a comment stating "Used by mediator. Not junk. Do not delete." But in a way, I don't see much difference between this:
var view = new View();
view.sharedType = type;
var med:ViewMediator = new ViewMediator(view);
facade.registerMediator(med);
and this:
var view = new View();
var med:ViewMediator = new ViewMediator(view);
med.sharedType = type;
facade.registerMediator(med);
except that I know we have discussed not exposing properties or methods on the mediator. If this risks just becoming a debate about "worse is better" let's leave it at that. I don't need to waste your time. I intend to follow your ultimate recommendation regardless. But if the issues I raised would affect your recommendation, then I hope you will share your thoughts. If not, I am just going to proceed with your first suggestion.
Thanks again for any feedback.
*1 There is a reason I have become militant about the mediator constructor being limited to (name, viewComponent). That is because I have had people put all kinds of crap in there, including a second view component (remember, view/control panel pair). Fed up with this, I made it a rule that the constructor is never to deviate from: (name=NAME, viewComponent=null).