java - Do I need an interface that has only one implementation? -
i have interface, has 1 implementation. following pair represents simple java object. want remove interface , use object directly. want understand when it's needed , why designed in way. done not ease unit test coverage. so, why there interface 1 implementation in project? thanks.
an interface useful when might extend/change project. instance, if start project storing data in text file, , decide change doing database. if both of these implementations of same interface, swapping first out second simple. case of swapping concrete implementation in class uses it. instance, changing
istorage storage = new filestorage();
to
istorage storage = new dbstorage();
whilst may seem pointless have interface single implementation, may save lot of refactoring effort later.