Monday, December 21, 2015

Try to avoid using Static Methods in your code

I have been coming across allot of static code in the projects I work on.  It really makes practicing TDD, or any unit testing, a pain because static methods are not easily mocked.   Static methods also force your code to be highly coupled.  

A better approach is to not use static methods and instead use dependency injection.   This lends itself to being a better testable decoupled approach. 

Here are a few articles I have come across that do a pretty good job better explaining why you should try to avoid using Static in object oriented languages:

No comments:

Post a Comment