Java Reference
In-Depth Information
81
Chapter 3 Implementing Classes
C HAPTER G OALS
ȗ To become familiar with the process of implementing classes
ȗ To be able to implement simple methods
ȗ To understand the purpose and use of constructors
ȗ To understand how to access instance fields and local variables
ȗ To appreciate the importance of documentation comments
G To implement classes for drawing graphical shapes
In this chapter, you will learn how to implement your own classes. You will start
with a given design that specifies the public interface of the classȌthat is, the
methods through which programmers can manipulate the objects of the class. You
then need to implement the methods. This step requires that you find a data
representation for the objects, and supply the instructions for each method. You then
provide a tester to validate that your class works correctly. You also document your
efforts so that other programmers can understand and use your creation.
81
82
3.1 Levels of Abstraction
3.1.1 Black Boxes
When you lift the hood of a car, you will find a bewildering collection of
mechanical components. You will probably recognize the motor and the tank for
the wind-shield washer fluid. Your car mechanic will be able to identify many other
components, such as the transmission and the electronic control moduleȌthe
device that controls the timing of the spark plugs and the flow of gasoline into the
motor. But ask your mechanic what is inside the electronic control module, and you
will likely get a shrug.
Search WWH ::




Custom Search