If I have to choose between static method and creating an instance and use instance method, I will choose static methods always. but what is the detailed overhead of creating an instance?
for example I saw a DAL which can be done with static classes but they choose to make it instance now in the BLL at every single call they call something like.
new Customer().GetData();
how far this can be bad?
Thanks
The performance penalty should be negligible. In this blog entry someone did a short benchmark, with the result that creating 500,000 objects and adding them to a list cost about 1.5 seconds.
So, since I guess
new Customer().GetData();will be called at most a few hundred times in a single BLL function, the performance penalty can be ignored.As a side note, either the design or the naming of the class is broken if
new Customer().GetData();is actually used: If classCustomerjust provides the means to get the data, it should be called something different, likeCustomerReader(for lack of a better name). On the other hand, ifCustomerhas an instance state that actually represents a Customer,GetDatashould be static — not for reasons of performance, but for reasons of consistency.