Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • To add to this - "We don't start with multiple implementations, we start with one and we prepare for future extension" can't be solved with YAGNI. Often, these interfaces are made for the purpose of dependency inversion - there will never be multiple implementations of FooCalculator, but we want to be able to swap out a binary to update the version of FooCalculator without having to rebuild its consumers. Commented Apr 22, 2024 at 19:55
  • @TimC: Hot-swapping binaries is way more uncommon than the use cases for interface abstraction, even if a single implementation. Also, it doesn't really add anything to the equation, because you can just as easily hot-swap the binary with a class implementation. Secondly, if there is provably never a second implementation, then the interface is actually irrelevant to have. However, it's impossible to really judge the future to that degree of certainty. Mocks are often the immediate secondary implementation to justify the interface's existence even when only one real implementation exists. Commented Apr 23, 2024 at 23:45
  • Iterface is public facing, so it's name should be a primary concern, not class's. Therefore, if naming is a concern, and one has to follow the idea behind this answer, instead of "I" in interface name, they should use "Impl" in class name. Commented Jul 16, 2024 at 0:05
  • @Basilevs: It can be argued both ways. This is a holy war of subjective opinions with no technical relevance either way. Abstract fields like that of software engineering are very prone to different people having different mental models, and what clashes for one person makes sense for another. This isn't about finding the right argument as much as it is about following the overall consensus (which unfortunately has been split across languages) Commented Jul 16, 2024 at 5:01