Java Reference
In-Depth Information
1
// Exercise the IntCell class
2
3
public class TestIntCell
4
{
5
public static void main( String [ ] args )
6
{
7
IntCell m = new IntCell( );
8
9
m.write( 5 );
10
System.out.println( "Cell contents: " + m.read( ) );
11
12
// The next line would be illegal if uncommented
13
// because storedValue is a private member
14
// m.storedValue = 0;
15
}
16
}
figure 3.3
A simple test routine
to show how
IntCell
objects are accessed
With no visibility modifier, we have package-visible access, which is discussed in
Section 3.8.4. There is also a fourth modifier known as
protected
, which is dis-
cussed in Chapter 4.
javadoc
3.3
When designing a class, the
class specification
represents the class design and
tells us what can be done to an object. The
implementation
represents the inter-
nals of how this is accomplished. As far as the class user is concerned, these
internal details are not important. In many cases, the implementation repre-
sents proprietary information that the class designer may not wish to share.
However, the specification must be shared; otherwise, the class is unusable.
In many languages, the simultaneous sharing of the specification and
hiding of the implementation is accomplished by placing the specification
and implementation in separate source files. For instance, C++ has the class
interface, which is placed in a
.h
file and a class implementation, which is in
a
.cpp
file. In the
.h
file, the class interface restates the methods (by provid-
ing method headers) that are implemented by the class.
The
class specifica-
tion
describes what
can be done to an
object. The
imple-
mentation
repre-
sents the internals
of how the specifi-
cations are met.
Java takes a different approach. It is easy to see that a list of the methods in a
class, with signatures and return types, can be automatically documented from the
implementation. Java uses this idea: The program
javadoc
, which comes with all
Java systems, can be run to automatically generate documentation for classes. The
output of
javadoc
is a set of HTML files that can be viewed or printed with a
browser.
The
javadoc
pro-
gram automatically
generates docu-
mentation for
classes.
Search WWH ::
Custom Search