Question

I am programming an instant messaging library for MSN Messenger, and I have a simple question about raising events.

When logging in, should I be raising UserAdded for each user that is synchronized (already on the contact list), or should the UserAdded event be reserved for when a new user has been added to the contact list via the AddUser method? Should I perhaps use another event, UserDownloaded for when a user is downloaded?

Similarly, when I call logout, should I call UserRemoved?

I hope this makes sense.

Thank you

Was it helpful?

Solution

This is a more general design question and it may depend on your specific case - e.g. what do you plan to use the events? What information does the user of the library need?

I think that triggering the event when a user is added from any source (both locally and when a new user is downloaded) is more useful, because you could use the event as a notification of when you need to update the list of users (for example). The event could also carry some YourEventArgs information which would contain information about the source (local vs. downloaded).

Triggering the event when some method is called may not be as useful (if the method is called by the user of the library), because the user of the library will probably know that he's calling the method (so he doesn't need to be notified about that).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top