I'm working on a web app built in Flash AS3.
At a high level - the app has a main screen, and several "modal dialog"-type screens that pop-up to manage various user interactions.
(This is a similar pattern I use in most of the apps I develop...)
Typically - when the user clicks a UI control on the dialog screen (e.g., button, text box, slider bar, etc.) - the main screen needs to react, or manage the consequences.
It seems like there are two general ways to handle this:
- Have the dialog screen dispatch events that the main screen listens for
- Allow the dialog screen to call functions in the main screen when those controls are clicked (which requires that the dialog screen maintain a reference to the main screen, and that the functions in the main screen are public)
In general - I understand that one of the key benefits of the first method is that the dialog screen isn't so tightly coupled; it's only responsibility is to broadcast the event. This would allow me to more easily use the dialog class in other contexts, or applications.
But for many RIAs I develop - a particular screen is SO SPECIFIC to the the application that there's no chance I'd ever reuse it in another application. So, the "easy re-use" benefit is minimal.
So - if you eliminate that benefit - which method is actually better? (More performant, less resource-intensive?)
For example - if I use events, then Flash needs to manage many listeners for events that may never occur. So - it might be more efficient if the dialog window could call a function in the main screen directly, instead of dispatching an event.
Which method is a better practice? What other benefits/pros/cons are there for each method?
Many thanks in advance.