PDA

View Full Version : Custom events best practice?


blu3
03-31-2010, 09:47 AM
Hi everyone,

I have a question regarding custom events best practice. If i have a single object that can dispatch two or more custom events is it better to have
a single custom event class with those event in it or to separate every custom event to its own class? How do you handle situation like this? I am asking this because even if those two or more events are similar and are attached to same object they could have different parameters i want to pass to them so it could be a bit confusing if i use one custom event class and pass those parameters all the time.

Cheers

wvxvw
03-31-2010, 01:02 PM
If I must have custom events, I make them so the event accomplishes some goal, rather then serves some specific object. Example: I have a UIEvent which can have types "scroll", "expand", "collapse" etc. So each component that may scroll expand or collapse would dispatch a UIEvent of the type corresponding to what it does.
However, performance-wise, it's best to have fewer event and use simple callbacks when possible.