DAO pattern - use Static or non Static methods?

可紊 提交于 2019-12-01 14:35:09

Try this: write a unit test for the code you have that uses this DAO.

One of your goals should be tests that pass very quickly, and don't have dependencies on external resources (a good unit test should not require an actual database to be present.) So instead of having your test call the real DAO, create a mock DAO that returns a fixed language entity, and have your test code use the mock instead of the real DAO. Does that still work? Can you successfully substitute your mock DAO for the real DAO if the real DAO has static implementations of these methods?

Statics make your code brittle. Avoid them when you can.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!