Dear All,
Greetings !!!
I just have been seeing few projects recently. There is a strange feeling I have.
We normally (if we are using Spring, then most of the times) expose our libraries to application with interface rather directly with class. Sure I know that if we have multiple implementation of methods we should use interface, I also understand the conditions when we should choose abstract class over interface but to my surprise I fail to understand
exposing entire class structure with interfaces. For example
If we are use Action (Struts) and Controller(Spring) , in either case we inject Service Interface.
Service Interface is accessed by its Impl method ,which injects DAO Interface
DAO Interface is accessed by its Impl
Of course you may add few more layers viz. Business and access that with BusinessImpl class .*
I understand the reason if you have multiple class implementing this interface giving it real meaning, but why there is 90 % times one to one mapping of One class One interface might be fore sighting future to add some more classes with similar methods ,again a future which 95% + times never comes in any project I guess.
Of course I guess you will not answer me saying it’s done because of IoC principal because we anyway if need only one class ,we still can follow IoC and can inject direct class object does no harm and even reduce code and load in JVM (Load in JVM I am still not sure about , Since they say Interface don’t create objects but JVM load balancer take reverse hit using so many interfaces and classes with only one to one mapping)
* Impl is just the most common name you can use whatever.