What is main reason of coding with interfaces not with the implemented classes in java. i don't What is strong reason behind it.. can anyone guide me
Asked
Active
Viewed 32 times
1 Answers
1
The reason is the Dependency Inversion principle.
In a nutshell:
- High-level modules should not depend on low-level modules. Both should depend on abstractions.
- Abstractions should not depend on details. Details should depend on abstractions.
An interface is an abstraction, an implementation is a detail. By making your program elements depend on interfaces, you free yourself from depending on details. When you don't depend on details, then if the details change, the rest of the program doesn't need to be recompiled.
See the linked wiki page for a more detailed explanation.

janos
- 120,954
- 29
- 226
- 236