Why do some APIs provide mostly interfaces and not classes?
Some Java APIs provide a large number of interfaces and several classes. For example, the Stellent / Oracle UCM API consists of approximately 80% interfaces / 20% classes, and many of the classes are just exceptions.
What is the technical reason for preferring interfaces over classes? Is this just an attempt to minimize grip? Improve encapsulation / information hiding? Something else?
a source to share
They are intended for third parties to ensure implementation.
A classic and successful example is JDBC (22 interfaces 7 concrete classes)
The idea is to provide .... a programmer's interface (API) so that clients (those using the code) can freely pass to the functions that the API provides without worrying about the underlying implementation.
Another reason is that there might be an existing provider (i.e. FutureSQL) that still doesn't exist, but it can implement these interfaces and you can use it.
a source to share
The framework / API was probably designed with Dependency Injection , extensibility, low coupling and high cohesion
a source to share
One of the best examples is the java.sql package.
The reason is this: when the designer has a clear idea of ββwhat needs to be done and how the entire application [not yet developed] is structured, they expose that idea through the API as a bunch of interfaces.
For example: when SUN (now oracle :-() publishes an API for JDBC, the entire SQL package (well, most of it) is just interoperable interfaces that are very well defined, but the actual DB / RDBMS provider knows what to do to they achieve the expected results in the API.
Hence, you can write ur java and DB interaction separately, while the database provider writes the database separately. The vendor just has to write a driver that conforms to the API (s) standard without telling you how they did it.
However, ur and DB app will deal with any problem [and most of the time; -)]
This is a long answer, but hope it helps. Thanks,
Ayusman
a source to share