Java Reference
In-Depth Information
objects. In those chapters, your job is analogous to the car parts engineer who
specifies how an engine control module should function.
S
ELF
C
HECK
1.
In
Chapters 1
and
2
, you used
System.out
as a black box to cause
output to appear on the screen. Who designed and implemented
System.out
?
2.
Suppose you are working in a company that produces personal finance
software. You are asked to design and implement a class for
representing bank accounts. Who will be the users of your class?
3.2 Specifying the Public Interface of a Class
In this section, we will discuss the process of specifying the behavior of a class.
Imagine that you are a member of a team that works on banking software. A
fundamental concept in banking is a bank account. Your task is to understand the
design of a
BankAccount
class so that you can implement it, which in turn allows
other programmers on the team to use it.
You need to know exactly what features of a bank account need to be implemented.
Some features are essential (such as deposits), whereas others are not important (such
as the gift that a customer may receive for opening a bank account). Deciding which
features are essential is not always an easy task. We will revisit that issue in
Chapters
8
and
12
. For now, we will assume that a competent designer has decided that the
following are considered the essential operations of a bank account:
In order to implement a class, you first need to know which methods are required.
ȗ Deposit money
ȗ Withdraw money
ȗ Get the current balance
85
86
In Java, operations are expressed as method calls. To figure out the exact
specification of the method calls, imagine how a programmer would carry out the