where to define UI event handlers

It depends.

If the event only affects the UI component itself that broadcasts it (like in a simple scenario of a button being rolled over) but not others, the event handler can be part of that UI component methods.

But in most cases, the event will possibly affect other elements in the app. Like clicking one button will require the visual state change of another button in the same group, as in the case of a menubar. The event handler would be better end up in another place, or in more than one place. For example, a layout manager (menubar class) will handle the click event of individual buttons, while the button itself will define some handlers that’s always going to be executed regardless of the state of other elements in the group. In either cases, the UI component’s major responsibility will be just to provide API for changing the state of itself. It’s up to the layout manager to handle the event.

Like in a real analogue, a team member only tells what she is capable of doing; it’s up to her manager to decide what she really does and make the final call.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: