Using Static methods or none static methods in Dao Class?

前端 未结 5 1512
庸人自扰
庸人自扰 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 07:03

    Assigning new DataAccessor object to static DataAccessor reference in every method will result in concurrency issues. You can still have the static methods in SampleDao class but make sure you remove the static reference to DataAccessor. To use DataAccessor, create a local instance. This way you can avoid concurrency issues. The disadvantage here is every time you call the static method, an instance to DataAccessor is created.

    Daos in most cases are stateless.In those cases I see no point in having non static methods in Daos, because we need to create an instance of that dao to access its method.

提交回复
热议问题