A well-designed module hides
all of its implementation details, cleanly separating its API from its implementation.
Modules then communicate only through their APIs and are oblivious to
each others’ inner workings.
The user of a module should
never be surprised by its behavior. Modules should be as small as possible but no
smaller. (As used in this book, the term module refers to any reusable software
component, from an individual method to a complex system consisting of multiple
packages.) Code should be reused rather than copied. The dependencies between
modules should be kept to a minimum.
The term exported API, or simply API, refers to the classes,
interfaces, constructors, members, and serialized forms by which a programmer
accesses a class, interface, or package. (The term API, which is short for application
programming interface, is used in preference to the otherwise preferable term
interface to avoid confusion with the language construct of that name.) A programmer
who writes a program that uses an API is referred to as a user of the API.
A class whose implementation uses an API is a client of the API.
Please explain the terms "API" and "module" as in used here. Also, I don't understand by what the author means when he is saying "separating its API from its implementation" & "Modules then communicate only through their APIs" in the first para.
The API should appear identical to an interface with the same methods.
Eshan Kapoor wrote:How to separate API from its implementation? By implementation do we mean the code that goes inside the methods of a class?
And that's why, when you're writing a Java class, you go (or you should go) to great lengths to hide the HOW (ie, the implementation) from the users of your class.
Eshan Kapoor wrote:In order to do this, taking your Sorting example, do I need to first make an interface with some methods, then create a class which implements those methods and adds the logic - Quicksort.
And then finally, the class which needs to sort the customers uses the implementing class? Just like List--> ArrayList ---> and finally we use ArrayList in our classes.