Top-Down Design: From Goal to Helpers

Top-Down Design is a planning approach that starts with a program's overall goal and repeatedly divides it into smaller responsibilities. You use it when a problem is too large to translate comfortably into code all at once. In modular programming, these responsibilities become functions, giving you a plan for what each part should accomplish before you work out its detailed instructions.

Start with the whole task

Begin by stating what the completed program should achieve. Include the information it receives and the result it should produce. For example, an event-report program might receive registrations and session capacities, then produce attendance totals and warnings about full sessions.


Next, identify a few major responsibilities that together accomplish that goal. A useful first division is reading registrations, summarizing attendance and presenting the report. These names describe meaningful jobs rather than individual instructions such as adding one number or printing one line.


A top-level driver can express this plan by arranging the major tasks. Its purpose is to make the overall job understandable. You should be able to read the plan and explain how the program reaches its goal without inspecting every calculation.



Refine one responsibility at a time

Stepwise refinement means adding detail to a task by replacing it with smaller tasks that explain how it will be accomplished. After outlining the whole program, inspect each responsibility separately. Summarizing attendance might require counting attendees and identifying full sessions.


A program goal branches into three responsibilities, with one responsibility divided into two smaller tasks.


Each connection in this hierarchy means that the smaller task contributes to the larger one. It does not automatically mean that the task below runs immediately after the task above. A design hierarchy describes responsibility, not execution order. Your eventual program still needs an appropriate order for reading information, calculating results and presenting them.


For every proposed function, describe the information it needs and the result it provides. You do not need detailed syntax to make this decision. Counting attendees needs registration data; identifying full sessions also needs session capacities. Stating those needs reveals missing information before implementation begins.


Example: If a report must compare attendance with room capacity, a plan that only reads attendee names is incomplete. Refinement exposes the need to obtain capacity information as well.

Choose useful boundaries

Stop refining a task when its instructions are clear enough to implement and check directly. There is no universal number of lines that makes a function the right size. A short calculation may already be clear, while a task involving several separate decisions may benefit from more helpers.


Design choice

Why it helps or causes difficulty

One function summarizes attendance

Gives related calculations a clear home

One function reads data, calculates totals and formats every page

Combines responsibilities that may change independently

Several functions each perform one trivial instruction

Adds boundaries without necessarily making the plan clearer

One shared helper applies a repeated rule

Gives later rule changes one consistent place to happen


A useful boundary groups work that serves one clear purpose. It also makes likely changes easier to locate. Changing a report's wording should usually affect presentation work; changing how attendance is counted should affect the relevant calculation.



Your first plan can change as you learn more. Refinement may reveal that a task needs another helper or that two proposed helpers perform the same job. Revise the plan while preserving a clear connection between each helper and the overall goal.

What to remember

  • State the complete goal before choosing detailed instructions.
  • Divide the goal into meaningful responsibilities.
  • Refine unclear tasks and identify the information they need.
  • Stop when each task is manageable to implement and check.
  • Use boundaries that make changes easy to locate.

Example: Planning a Campsite Invoice

A campsite needs a program that reads a booking and displays its invoice. A booking contains the number of nights, the nightly rate, a discount percentage and a cleaning fee. Use task decomposition, splitting a complete job into named responsibilities, to plan the program before writing detailed code.


For a test booking, a guest stays 4 nights at CAD 35 per night, receives a 10% discount and pays a CAD 20 cleaning fee. The discount applies only to nightly charges. Assume there are no taxes or other charges.


a) Propose three major responsibilities for prepareInvoice. Refine its calculation responsibility into three smaller helpers.


First, separate obtaining information, calculating the amount and presenting the result. The three major responsibilities are readBooking, calculateInvoice and showInvoice.


Next, refine calculateInvoice around the actual billing rules:

  • calculateNightlyCharge multiplies nights by the nightly rate.
  • calculateDiscount determines the reduction from the nightly charge and discount percentage.
  • addCleaningFee adds the cleaning fee to the discounted nightly charge.

The coordinating calculation subtracts the discount before using addCleaningFee. This keeps the cleaning fee outside the amount eligible for the discount.


An invoice program branches into reading a booking, calculating an invoice and showing it, with three calculation helpers.


The resulting plan has three major responsibilities, with the invoice calculation divided into three helpers. The hierarchy records responsibility; the accompanying description supplies the necessary calculation order.


b) Follow the calculation plan for the test booking. State each intermediate amount and the final invoice total.


First, calculateNightlyCharge uses the number of nights and the nightly rate. The nightly charge is ________.


C=(4 nights)(35 CAD/night)=140 CAD.C=(4\text{ nights})(35\text{ CAD/night})=140\text{ CAD}.


Next, calculateDiscount uses the nightly charge rather than the charge including cleaning. The discount is ________.


D=0.10(140 CAD)=14 CAD.D=0.10(140\text{ CAD})=14\text{ CAD}.


The coordinating calculation subtracts the discount. The discounted nightly charge is ________.


C−D=140 CAD−14 CAD=126 CAD.C-D=140\text{ CAD}-14\text{ CAD}=126\text{ CAD}.


Finally, addCleaningFee adds CAD 20. The governing calculation and its result are


T=C−D+F=140 CAD−14 CAD+20 CAD=146 CAD.T=C-D+F=140\text{ CAD}-14\text{ CAD}+20\text{ CAD}=146\text{ CAD}.


The final invoice total is CAD 146. As a check, the undiscounted invoice would be CAD 160, so the result is lower by exactly the CAD 14 discount.


c) The campsite now determines cleaning fees from the campsite zone instead of reading a fixed fee from each booking. Identify the calculation responsibility to refine and the additional information the plan needs.


The changed rule concerns the cleaning fee. Refine addCleaningFee so that it obtains the appropriate fee through a smaller helper named determineCleaningFee, then combines that fee with the discounted nightly charge.


DetermineCleaningFee needs the campsite zone and the fee schedule for those zones. ReadBooking therefore needs to obtain the zone instead of a fixed cleaning-fee amount, and the overall plan must make the fee schedule available to the calculation.


CalculateNightlyCharge and calculateDiscount retain their existing responsibilities because neither the nightly-price rule nor the discount rule has changed. ShowInvoice can continue presenting the calculated total.


The revised plan is to refine addCleaningFee with determineCleaningFee and provide the zone and fee schedule, while updating the booking information that the calculation receives.

A teacher needs a program that reads assessment scores from a file, calculates class summaries and displays a report. Which division best suits the initial high-level plan?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A library is planning a program to produce a weekly borrowing report. Arrange these nested planning notes from the broadest task to the most detailed responsibility. Each successive note belongs within the preceding task; this is a refinement sequence, not a runtime sequence.

  1. 1.

    Produce the weekly borrowing report.

  2. 2.

    Calculate the total number of loans for the week.

  3. 3.

    Add the seven daily loan counts to obtain the weekly total.

  4. 4.

    Summarize the week's borrowing activity.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A school plans the loan-report program shown below. Every box has its own function definition, including the top-level function and all coordinators. The completed program runs twice each day without adding or changing definitions. How many distinct function definitions does the plan require? Answer as an exact whole number of functions.


A loan-report design has one root task, three coordinating tasks and smaller tasks beneath each coordinator.


Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice