Programming and Problem Solving with Java

(やまだぃちぅ) #1

(^270) | Object-Oriented Software Design and Implementation


6.1 Software Design Strategies


As we have stressed several times, the programming process consists of a problem-solving
phase and an implementation phase. The problem-solving phase includes analysis(analyz-
ing and understanding the problem to be solved) and design(designing a solution to the
problem). Given a complex problem—one that results in a 10,000-line program, for example—
it’s simply not reasonable to skip the design process and go directly to writing Java code. What
we need is a systematic way of designing a solution to a problem, no matter how
complicated the problem is.
We’ve used the term object-oriented design (OOD)frequently throughout this
book, and we have employed OOD in an intuitive manner in the Case Studies. In
this chapter, we describe in a more methodical way and see how OOD can be used
in designing solutions to more complex problems.This methodology helps you cre-
ate solutions that can be easily implemented as Java applications. The resulting
applications are readable, understandable, and easy to debug and modify. Java
was developed in part to facilitate the use of the OOD methodology. In the next two
sections, we present the essential concepts of OOD; throughout the rest of the
book, we will expand our treatment of this approach. At times OOD is used in con-
junction with a second, older methodology, which we also discuss in this chapter—
functional decomposition.
OOD focuses on the entities (objects) in a problem. Using this approach, we solve
a problem by identifying the components that make up a solution and determin-
ing how those components interact. The result is a design for a set of objects that
cooperate to solve a problem.
In contrast, functional decomposition views the solution to a problem as a task
to be accomplished. It focuses on the sequence of operations that are required to complete
the task. When the problem requires a series of steps that is long or complex, we divide it
into easier-to-solve subproblems. Functional decomposition is the method that we have
used to this point to break our simple problems into sequences of steps that the computer
can follow. This strategy can be used to develop algorithms for an object’s methods.
In most large problems, we naturally find entities that we wish to represent in our code.
For example, in designing an application that manages a checking account, we might iden-
tify checks, deposits, account balances, and account statements as entities. These entities
interact through messages. For example, a check could send a message to the balance en-
tity that tells it to deduct an amount from itself. We didn’t list the amount in our initial set
of objects, but it may be another entity that we need to represent.
This example illustrates a common approach to OOD. We begin by identifying a set of ob-
jects that we think are important in a problem.Then we consider some scenarios in which the
objects interact to accomplish a task. In the process of envisioning how a scenario happens,
we identify additional objects and messages. We keep trying new scenarios until we find that
our set of objects and messages is sufficient to accomplish any task required by the problem.

Object-oriented design A
technique for developing soft-
ware in which the solution is ex-
pressed in terms of
objects—self-contained entities
composed of data and
operations on that data that in-
teract by sending messages to
one another
Functional decomposition A
technique for developing soft-
ware in which the problem is di-
vided into more easily handled
subproblems, the solutions to
which create a solution to the
overall problem T

E


A


M


F


L


Y


Team-Fly®

Free download pdf