4. Java Program Design and Development

4.2. Designing Good Programs

Programming is not simply a question of typing Java code. Rather, it in- volves a considerable amount of planning and careful designing. Badly designed programs rarely work correctly. Even though it is tempting for novice programmers to start entering code almost immediately, one of the first rules of programming is

In other words, the more thought and care you put into designing a pro- gram, the more likely you are to end up with one that works correctly. The following subsections provide a brief overview of the program develop- ment process.

The Software Engineering Life Cycle

Software engineering is the process of designing and writing software. The software life cycle refers to the different phases involved in the design and development of a computer program. Our presentation of examples in the book will focus on four phases of the overall life cycle. In the spec- ification phase we provide a statement of the problem and a detailed de- scription of what the program will do. In the design phase we describe the details of the various classes, methods, and data that will be used in the program. The implementation phase refers to the actual coding of the program into Java. In the testing phase we test the program’s performance to make sure it is correct, recoding it or redesigning it as necessary.

Figure 1.1 gives a more detailed overview of the program development process, focusing most of the attention on the design phase of the software

 

SECTION 1.2 Designing Good Programs25

life cycle. It shows that designing an object-oriented program is a matter of asking the right questions about the classes, data, and methods that make up the program.

Overall, the program development process can be viewed as one that repeatedly applies the divide-and-conquer principle. That is, most pro- gramming problems can be repeatedly divided until you have a collection of relatively easy-to-solve subproblems, each of which can be handled by

an object. In this way the program is divided into a collection of interact-Divide and conquer

ing objects. For each object we design a class. During class design, each object is divided further into its variables and methods.

 

 

 

 

Program Development Process

 

 

Problem Decomposition

What objects will be used and how will they interact with each other?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Coding into Java

Stepwise refinement Fixing syntax errors

 

 

 

 

 

 

 

 

When should we stop subdividing? How much of a task should be assigned to a single object or a single method? The answers to these and similar questions are not easy. Good answers require the kind of judg- ment that comes through experience, and frequently there is more than one good way to design a solution. Here again, as we learn more about


Figure 1.1: An overview of the program development process.

 

object-oriented programming, we’ll learn more about how to make these design decisions.