This question already has an answer here:
- Why are interfaces useful? 19 answers
I'm working on a set of automated tests that we use internally at work. Lately, we've been designing classes that implement interfaces in addition to inheritance.
As I understand it, interfaces in Java are used to fulfill a contract. A class that implements an interface must include implementations of any members of that interface. This works really well for building libraries or objects that are meant to be used by outside teams or individuals since it guarantees certain methods will be present.
What about code that's entirely kept within a single team in a single location? (Assume this code will stay internal, or else this question changes entirely.) If I can simply go to my VCS history or ask a team-member about changes to code, do I really need to enforce these changes using interfaces? Even if a team is large, you could still develop conventions or tests to verify things. I feel like we're just making more work for ourselves by using interfaces, but maybe there are additional arguments.
NOTE: This project is a Java project and will stay that way. Interfaces here are instances of
interface with all the syntax and rules that apply.