Was asked today why I used code like this for my bll classes in an asp.net app:
public class StudentBll
{
public static DataTable GetStudents()
{
return DBHelper.ExecuteSp("GetStudents");
}
public static DataTable GetStudentById(int studentId)
{
return DBHelper.ExecuteSp("GetStudentById", studentId);
}
}
instead of
public class StudentBll
{
public DataTable GetStudents()
{
return DBHelper.ExecuteSp("GetStudents");
}
public DataTable GetStudentById(int studentId)
{
return DBHelper.ExecuteSp("GetStudentById", studentId);
}
}
Only thing I could think of was that
A) Performance A slight increase (not sure of the specifics)
B) Readability
StudentBll.GetStudents(); rather than
StudentBll studentBll = new StudentBll();
studentBll.GetStudents();
I wasn’t too confident in those answers, however. Anyone care to enlighten me?
With respect to performance, if you can’t show what the increase is, then it does not support your claim. One could also argue that the performance gain by a static method call vs an instance method call is negligible to that of the round-trip travel & database time.
You’ve also locked down your implementation (or at least forced the consumers to do something harder to modify). If you lost the static methods and code to an interface, testers and developers of different tiers could build mocks so they wouldn’t be forced to use whatever you provide them.