Data Structures in Program Design
Top-down programming makes a large problem manageable through repeated decomposition.
A Large Task With No Obvious First Step
Suppose you are handed a programming task that is very large, and no single step seems to solve it. Where do you begin? Programmers face this situation constantly, and it is the situation that top-down programming was developed to handle. The method makes a large task manageable by starting with the complete problem and dividing it into smaller jobs.
What do you think happens?
When you face a large programming task, which should you consider first: the small details of individual instructions, or the complete problem as a whole?
Reveal answer
The complete problem as a whole
Top-down programming begins with the complete problem, divides it into smaller jobs, and keeps dividing each job until the remaining tasks can be solved directly. The approach focuses attention on the structure of the work before the individual details.
Breaking a Problem Down Top-Down
Top-down programming is a method in which the programmer begins with the complete problem, divides it into smaller jobs, and continues dividing each job until the remaining tasks can be solved directly.
The important movement is from broad to specific. The programmer first decides what major work the system must perform, then refines each part. Each refinement pass produces smaller pieces that are easier to reason about than the original whole. The method does not claim that every programming problem has one perfect breakdown. Its value is that it gives the programmer a practical way to organize a large problem.
The diagram shows only the first split. In practice, each major job is divided again, and that division continues until a piece is simple enough to solve directly. Notice that the diagram describes the work to be done. It says nothing yet about how the program's information is organized, a point the rest of this article develops.
Tracing a Registration Plan
The source describes a program that must manage a collection of event registrations. Follow how a top-down plan would handle it, one step at a time.
Planning an Event Registration Program Top-Down
A program must manage a collection of event registrations. Produce a top-down plan for it and identify what that plan settles and what it leaves open.
- 1Start with the complete problem
The whole task is managing a collection of event registrations.
- 2Divide into major jobs
A top-down plan might identify three jobs: adding a registration, removing one, and producing a report.
- 3Check what the plan describes
These activities describe what the program does. They are the operations, which are the instructions side of the design.
- 4Check what the plan leaves open
The three activities do not, by themselves, settle how the registration information is designed as data. The plan is useful but incomplete.
The top-down plan produces a clear list of operations, but the question of how registration information should be organized as data has not yet been answered.
Why Top-Down Planning Is Valuable but Incomplete
Top-down programming is not presented as a bad method. It is a valuable and often-used way to solve problems. Its limitation is narrower than it might first appear. The method concentrates mainly on the instructions needed to solve the problem, and that focus can leave another design question underdeveloped: what data the program must manipulate and how that data should be organized. The limitation is not that decomposition is useless. It is that decomposition alone can give inadequate attention to data structures.
A top-down plan is usable before it is finished. Once the major jobs are identified, the programmer already has a structure to work from, and each refinement pass makes the next piece easier to handle. What the method does not guarantee is that the data side of the design has received equal attention.
The concept map makes the central point of the source visible. Subroutines describe organized pieces of work, control structures describe how that work proceeds, and data structures describe the data that the program manipulates. A design that plans only the first two areas can contain detailed instructions without an equally deliberate data design.
Where the Registration Plan Falls Short
The registration plan from earlier illustrates the gap. Re-examine what it covered and what it missed.
Common mistake Treating a list of operations as a complete program design
What it looks likeA plan lists adding a registration, removing one, and producing a report, and the programmer considers the design finished.
Why it failsThose activities describe what the program does. They do not, by themselves, settle how the registration information is designed as data.
Do this insteadAfter listing the operations, deliberately design the data structures that those operations manipulate.
Common mistake Assuming careful instructions compensate for unplanned data
What it looks likeThe subroutines and control flow are carefully planned, but the data the program stores receives little thought.
Why it failsIf the instructions are carefully planned but the program's data is not given comparable attention, the overall design is incomplete.
Do this insteadGive data structures comparable attention to subroutines and control structures.
Common mistake Rejecting top-down programming entirely because it is incomplete
Why a Tailored Design Resists Reuse
A second limitation appears when work from one project must support another. Strict top-down programming begins with a particular problem and divides that problem into pieces that are convenient for that situation. As a result, the final design tends to be specific to the original problem. A large portion of it may not fit a different project without extensive modification.
Reuse matters because producing high-quality programs is difficult and expensive. Programmers and the people who employ them therefore have a strong reason to reuse work that has already been produced. A design tightly fitted to one problem makes that goal harder to achieve.
The comparison points to the specific features that block reuse. The design is shaped by the original problem from the first division onward. Each piece is convenient for that one situation, so the pieces carry the original problem's shape into any new project. Reuse becomes a matter of extensive modification rather than straightforward transfer.
Designing Data Alongside the Plan
Return to the event registration program. Your top-down plan lists three jobs: adding a registration, removing one, and producing a report. Write two or three questions you would need to answer about the registration information itself before the design could be called complete. Focus on the data, not the operations.
Hints
- Ask what information each registration must contain for the report to be produced.
- Ask how the program should identify one registration when removing it.
- The source says the plan describes what the program does, but not how the registration information is designed as data.
Key Takeaways
- Top-down programming makes a large problem manageable by beginning with the complete problem and dividing it into smaller jobs, then continuing to divide each job until the remaining tasks can be solved directly.
- The method is valuable and often used, but its limitation is that it concentrates on instructions and can leave the data structures underdeveloped.
- A complete program design needs subroutines, control structures, and data structures planned together, since a design that plans only the first two areas is incomplete.
- A design shaped by one specific problem tends to be difficult to reuse in another project without extensive modification, and reuse matters because high-quality programs are difficult and expensive to produce.