I recently saw some code from a college teacher where he had something like this:
public void Button1_Click(blabla)
{
//His code was here.
}
Isn’t it considered better programming practice to call a method to do the dirty work, that way if the method changes you only have to change the method itself and not the event? (Less chance of breaking something)
public void Button1_Click(blabla)
{
DoSomething();
}
public void DoSomething()
{
//The actual code here.
}
You only need to extract the
DoSomethingifa) it’s functionality is needed somewhere else, or possibly
b) it’s quite a long piece of code.
If the event is the only place it’s used then there’s no real need to extract it.