We have a typical n-level Java application, and I noticed that our data access levels have DAOs that are of type FooDAO and FooDAOImpl. I was looking for an excuse for these two, and here is my analysis.
- If you had multiple implementations for the same interface, abstraction is useful. But considering that we have already made the choice of the structure that will be used for DAOImpl (say, iBATIS), is this really necessary?
- Proxy help through Spring. From what I'm compiling, classes that have interfaces can be approximated easily (along the JdkProxy path), rather than classes that don't have interfaces (where the cglib route is chosen), and one has a subclass of the class that needs to be proxied. The subclassification has its problems when the proxy class is final or does not have any default constructors - both of which are extremely unlikely at the data access level. Performance was a factor, but from what I hear it is no longer a concern.
- Help mockingly. Classes with interfaces are more suitable for bullying due to mocking frameworks. I only heard it, but did not see it in practice - so in fact you canβt count on it, but perhaps because of the same factors that were mentioned in No. 2 above.
With these points, I donβt feel the real need for a separate FooDAO and FooDAOImpl, where a simple FooDAO is enough. Feel free to fix any of the points I mentioned.
Thanks in advance!
java spring dao mocking
Kilokahn
source share