java - Do you extract interface out of any class that can be instantiated? -
is considered practice have every single class (excluding domain models) of application based off of interface? if class called within package?
update: based on comments, here sample scenario can think of, feel had been have classes based off interface.
a calculator class within parent package, calculations , uses class (printer) print out results, file system. suppose calculator class public, printer class has package protection. if want printer send result on http instead of writing file system?
if printer class based off of interface, , if injecting printer class using spring. had swapped out implementation new 1 easily.
not @ all.
interfaces best used plan provide various polymorphic implementations, or wish invert dependencies purpose of unit testing.
interfaces should created when necessary. should designed.
Comments
Post a Comment