I'm building a little library for timers, just for a bit of fun and as a training in some coding practices. I came across a question and I can't find a proper answer through google (yes, I looked thoroughly, unless I'm not aware of the correct terminology). In my timer I have a property
IsStarted
. I want to be notified when it's value changes (each time the
Start()
or
Stop()
action is called.
On one hand I have what I call named events. This is what I use now. Let me give you an example, it will illustrate what I mean more clearly than when I try to describe it.
(I call it named events because the events are named after what happens, in this case the event fires when the IsStarted property changed.)
public class MyTimer
{
private bool _isStarted;
public delegate EventHandler OnIsStartedChanged;
public bool IsStarted
{
get { return _isStarted; }
private set
{
_isStarted = value;
OnIsStartedChanged();
}
}
}
On the other hand I have
INotifyPropertyChanged. This will save me (when I work with a load of properties I want to monitor) a lot of work in the timer class, but will give me extra work when I have to implement the callback function.
The
ChangedProperty
event fires and now I have to see which property changed and what I want to do with each property.
Now I'm wondering what is the best way? What is the most standard compliant? What will give me the cleanest code? Or is it just a matter of personal taste?