Hey guys,
I just have a question regarding the separation of UI code from business/logic code. I always seem to get in trouble for putting to much code in form classes. I don't understand where the line is drawn between code that needs to be in form/UI code vs code that needs to be put in a separate class. Further it seems a bit over kill to have to create a separate class and do logic in there just to do something simple. Lastly, what is the point? I really don't understand what the big deal is. I know that it is good practice but I mean is it really that big of an issue? In the example below I am getting the time and bringing up a message box. Now normally I would put this into the form code:
Form1.cs (UI Code)
int hour = DateTime.Now.Hour;
if(hour == 12)
{
MessageBox.Show("It's time")
}
By definition this is logic so I need to make an entirely separate class to satisfy the "separation of UI" rule such as I have done below?
Form1.cs (UI)
timelogic timeClass = new timelogic();
if(timeClass.returnTime())
{
MessageBox.Show("It's time")
}
public bool returnTime()
{
int hour = DateTime.Now.Hour;
if(hour == 12)
{
return true;
}
return false;
}
It seems to be a bit over kill. I get even more confused because I am using logic within my form class to bring up a message box so am I breaking the rule? Can someone explain the proper method for separating logic/business code from UI code?