Java Reference
In-Depth Information
Figure 7.6
The user interface
of a software
To investigate how the CalcEngine class is used by other classes, it is useful to look at its interface .
Confusingly, we are now not talking about the user interface , but about the class interface . This
double meaning of the term interface is unfortunate, but it is important to understand both meanings.
The class interface is the summary of the public-method headers that other classes can use. It is
what other classes can see and how they can interact with our class. The interface is shown in
the javadoc documentation of a class and in the Documentation view in the editor. Code 7.4
shows the interface of the CalcEngine class.
Code 7.4
The interface of the
arithmetic logic unit
// Return the value to be displayed.
public int getDisplayValue();
// Call when a digit button is pressed.
public void numberPressed( int number);
// Call when a plus operator is pressed.
public void plus();
// Call when a minus operator is pressed.
public void minus();
// Call to complete a calculation.
public void equals();
// Call to reset the calculator.
public void clear();
Such an interface can be written before the full classes are implemented. It represents a sim-
ple form of contract between the CalcEngine class and other parts of the program that wish
to use it. The CalcEngine class provides the implementation of this interface. The interface
describes a minimum set of methods that will be implemented in the logic component, and
for each method the return type and parameters are fully defined. Note that the interface gives
no details of exactly what its implementing class will do internally when notified that a plus
Search WWH ::

Custom Search