From what I've read I'm not sure if I've got the naming convention for events and handlers correct. (there seems to be some conflicting advice out there).
In the two classes below can anyone tell me if I've got the naming right for the event, the method that raises the event and the method that handles the event?
public class Car
{
// is event named correctly?
public event EventHandler<EventArgs> OnSomethingHasHappened;
private void MoveForward()
{
RaiseSomethingHasHappened();
}
// is the named correctly
private void RaiseSomethingHasHappened()
{
if(OnSomethingHasHappened != null)
{
OnSomethingHasHappened(this, new EventArgs());
}
}
}
and the subscriber class:
public class Subscriber()
{
public Subscriber()
{
Car car = new Car();
car.OnSomethingHasHappened += Car_SomethingHasHappened();
}
// is this named correctly?
private void Car_SomethingHasHappened(object sender, EventArgs e)
{
// do stuff
}
}
Thanks in advance!