Using Static methods or none static methods in Dao Class?

前端 未结 5 1475
庸人自扰
庸人自扰 2020-12-30 06:22

Hi I generate Dao classes for some DB operations

in this manner making methods of Dao class as static or none static is better?

Using sample dao class belo

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-30 06:54

    I always prefer non static classes. Dependencies cannot be injected to an static class and unit tests are harder. Also, its clients cannot replace it with a test double when they are unit tested.

    http://googletesting.blogspot.com/2008/12/static-methods-are-death-to-testability.html

提交回复
热议问题