Java Reference
In-Depth Information
CLASS DIAGRAMS As you have learned, programs can be broken into
smaller pieces, called objects, which represent a real person, place, event, or
transaction. Object-oriented design is an approach to program design that iden-
tifies how groups of objects interact with each other in order to solve a problem.
A class represents the common structure and behavior shared by the same type
of objects. A modeling tool that helps developers visualize how a class works
within a program is called a class diagram. A class diagram illustrates the name,
attributes, and methods of a class of objects. The attributes of a class are prop-
erties used to define characteristics such as appearance. The methods of a class
are instructions that the class uses to manipulate values, generate outputs, or
perform actions. Many times, classes are individual program modules that often
can be reused by other programs.
The Shipping Charge Calculator requires that users access the program in
one of two ways: a windowed application or an applet. Rather than creating two
completely separate applications for these different users, the algorithm used to
solve the problem should be programmed only once. By centralizing the pro-
gram logic for the two application types, maintenance of the program is easier,
and the logic needs to be programmed only once, rather than twice. The algo-
rithm can be placed in a class. The Shipment class has an attribute that corre-
sponds to the input, shipment weight. The class requires one method,
getShipping(), that tells the class how to manipulate the input value and generate
the required output. Method names typically are represented with an active
verb phrase followed by parentheses. The getShipping() method performs the
calculation after the attribute, weight, is sent to the object by the program.
Figure 1-13 shows a class diagram of the Shipment class. Appendix A includes
a more detailed discussion of class diagrams.
Shipment
Commission
class name
shipWeight
attributes
getShipping()
methods
FIGURE 1-13
FLOWCHARTS Programmers often create a diagram called a flowchart ,
which graphically represents the logic used to develop an algorithm. Table 1-2
shows a standard set of flowchart symbols used to represent various steps, or
operations, in a program's logic. When you draw a complete flowchart, you must
begin with a terminal symbol connected by a flowline to the first logical step in
 
Search WWH ::




Custom Search