Thursday, October 1, 2009

Danger: Events

Before C# era, there were no such things as Events. But there were callbacks, ugly stuff to use. And now with C#, there are Events, comfortable, easy to use, subscribe, get notified from server, define event, fire it easy.

With C# there are 3 types of capabilities, class exposes:

Methods, Properties and Events.

 

Events=Methods with some extra subscription.

How do we decide, what Events are for and what Methods are for? More accurate question might be when to use Events and when Methods? The different between What and When might be the answer. Interested?

I think that the intention of Events is to let Client know WHEN something is done. This is a feedback, a follow up after Client was told WHAT to do.

And the intention of Methods is to let know Client WHAT to do.

So I try to consider these factors when defining Event and Method.

1 comments:

rubenhak said...

Very nice observation. Its a common mistake to misunderstand role/purpose of methods and events. Will recommend this article at the workplace.

Post a Comment