CS210 · Block 3 · Lesson 23

Software Design from Requirements

Decomposition · Header design · Ownership in interfaces · The design memo
At a glance: All semester we have handed you the decomposition: function signatures in a header, a spec naming each function. Today you do that work yourself. You will read a requirements document, identify the data and the actions, group them into modules, sketch headers with ownership notes, and write a short design memo. The lab is the rehearsal for your Team PEX design check-in.
Contents
  1. Lesson Objectives
  2. Assigned Readings
  3. Pre-Class Work
  4. Lesson Materials and Overview
  5. In-Class Work
  6. After Class
1. Lesson Objectives

By the end of this lesson, cadets will be able to:

  1. Decompose a problem statement into program modules and functions. (Outcomes 3, 7)
  2. Design header files that expose appropriate interfaces. (Outcome 7)
  3. Document design decisions in a written design artifact. (Outcomes 4, 7)
2. Assigned Readings

Complete before class. These set the vocabulary we will use.

Source Sections Why
Lesson 23 supplementary notes All sections The four-step process you will use today
DFCS C Programming Standard §2.2 (function header blocks), §8.5 (always free dynamically allocated memory) Today\'s touchpoint: ownership documented at the header
Beej-C Chapter 15 (Multifile Projects) revisit Skim. Refresher on what goes in .h vs .c
3. Pre-Class Work
Do this first
About 40 minutes total. The reading is short; the preparation for Team PEX takes the rest.
1
Read the Lesson 23 supplementary notes
Posted in Blackboard. Plan on 15 to 20 minutes. The notes walk through the four-step process for turning a requirements document into a design: extract nouns and verbs, group into modules, write the interface, document ownership. Bring questions to class.
2
Review the Team PEX topic list
The instructor-provided list of candidate Team PEX topics is posted in Blackboard. Read through it with your team. Talk about which two or three topics interest you most before class. The proposal is due TODAY, so come ready to commit.
3
Predict-the-design exercise (5 minutes)
Look at the requirements blurb below. Before class, list on paper or in a notes app: what are the data nouns, what are the action verbs, what would your modules be? You will compare your answers with what we build together in class.
Spec: Build a program that helps a cadet study from a deck of flashcards. The program reads a deck from a text file (one card per line, question and answer tab-separated). The cadet can start a study session, which presents cards in random order. For each card, the cadet types an answer; the program checks it and tracks correct/incorrect counts. At the end of the session, the program prints a summary and offers to save session results to a file.
4. Lesson Materials and Overview
Jump to
Slides Why this lesson The four-step process Header design Ownership in interfaces The design memo DFCS standard touchpoint

Slides

Lesson 23 slide deck (PDF)

Why this lesson exists

On every lab so far, the spec told you what functions to write. You implemented prototypes that someone else (your instructor) decided on. That work was important, but it skipped the question every real C developer asks first: how did you decide the program should look like THIS?

Today is the lesson where that question gets a process and a vocabulary. You have been doing the underlying skill all semester. At Lesson 6 you refactored a monolithic main into functions you named. At Lesson 19 you designed structs around the data they hold. At Lesson 20 you decided what belongs in a header. Each of those was decomposition in disguise. Lesson 23 is where it gets a name.

The lab is the rehearsal for your Team PEX design check-in. The widget walks you through a small example. The lab takes you through one yourself, with a written deliverable.

The four-step process

A repeatable way to go from a written requirements document to a sketch of the program:

  1. Read and underline. Read the requirements once for understanding. Read again with two colored pens: one for nouns (the data the program holds), one for verbs (the actions the program performs). Anything underlined twice is interesting.
  2. Group nouns and verbs into modules. Verbs that act on the same noun belong together. Nouns that the program owns end to end deserve their own type. A module is one or more verbs operating on a related set of nouns.
  3. Sketch the interfaces. For each module, write a header file. Function signatures. Comments that say what the function does, what the inputs mean, what the output means, and who owns any memory returned. Skip implementation.
  4. Document and check. Write a short memo explaining the choices. Then ask: if I hand this to a teammate, what is the first question they ask? Whatever it is, your memo should already answer it.

The widget in Section 5 walks you through every step on a small flashcard-study example before you tackle the lab.

What belongs in a header

A header is a contract. Anything you put in it is a public promise to the rest of the codebase. The smaller and more honest the header, the easier the program is to maintain.

Put in the header:

  • The header guard (Lesson 20).
  • Type declarations that callers need: typedef, enum, struct forward declarations.
  • Function prototypes that other files will call.
  • A function header block above each prototype (DFCS §2.2) explaining what it does, what each parameter means, what it returns, and who owns any returned memory.

Keep OUT of the header:

  • Anything declared static. It is internal by design.
  • Function implementations.
  • Variable definitions (declarations are fine when truly needed, with extern; this is rare).
/* deck.h */ #ifndef DECK_H #define DECK_H /* Opaque forward declaration: callers see Deck as a type, * but cannot inspect its fields. */ typedef struct Deck Deck; /* Read a deck from disk. Caller must free with free_deck(). * Returns NULL on file or parse error. */ Deck *load_deck(const char *filename); /* Release a deck previously returned by load_deck. */ void free_deck(Deck *d); #endif

Ownership lives in the interface

Any function that returns a pointer is making a statement about ownership. The header is where that statement gets written down. Three patterns cover most cases:

  • Allocator pattern. Function returns a heap pointer; caller must free it (or call a matching destructor). load_deck above is one. malloc, strdup, fopen are standard library examples.
  • Borrow pattern. Function returns a pointer INTO existing memory (a string inside a struct, a card inside a deck). Caller must not free; the pointer becomes invalid when the underlying object goes away.
  • Out-parameter pattern. Function takes a pointer to caller-allocated storage and writes through it. No allocation, no ownership transfer.

The doc comment on the header is where the pattern gets named. If a teammate has to guess, the header is wrong. This is exactly the DFCS §8.5 discipline: every malloc has a matching free, and the design says who calls each.

The design memo

The third deliverable today is a short written memo, about one page, that captures your design choices in prose. The lab template gives you a structure to fill in. The required sections:

  • Modules. Each module gets a one-sentence purpose statement.
  • Data structures. The types you defined and why.
  • Ownership notes. Who allocates, who frees, what borrows from what.
  • How will we test this? One concrete test case per function in your interface.
  • Open questions. What you would ask the customer if you had more time.

The testing section is not an afterthought. If you cannot name a test case for a function, your interface is underspecified: the function has no observable result, or the inputs are not well defined. Change the design before you write code.

DFCS C Programming Standard touchpoint

Today touches two sections of the standard:

  • §2.2 Function Header Block. Every prototype in a header carries a documented function header block: purpose, parameters, return value, and (today\'s addition) ownership of any pointer returned.
  • §8.5 Always free dynamically allocated memory. The standard is short ("free what you allocate"). The design discipline is longer: the header names who allocates and who frees, so by the time you implement, the ownership rules are already on paper.

See the Resources section for the full standard text.

5. In-Class Work
  • Opener: Kahoot retrieval (10 min). Quick review of L20 multi-file rules and L22 argv discipline before today\'s content.
  • Decompose walkthrough (25 min). Twelve guided design decisions on the flashcard-study spec. Below.
  • Interface design self-check (10 min). Eight questions on header design, visibility, ownership. Below.
  • Lab: Design a Wordle module (60 min). Read the requirements, produce wordle.h, DESIGN.md, and a skeleton main. GitHub Classroom assignment.
  • Submit Team PEX topic proposal (15 min). Teams finalize and submit their topic choice via the Blackboard PEX Proposal assignment.

Decompose Walkthrough

Twelve design decisions on a small flashcard-study spec. Read the spec in the right pane, then answer each prompt. The right pane records your decisions as you go.

Before you begin

Enter your name. It will appear on the completion screen so you can include it in your screenshot for the Lesson 23 reflection.

CS210 Lesson 23 · Design Decomposition Walkthrough

Twelve design decisions on a small flashcard-study spec. You will not write any C code here. You will read requirements, extract nouns and verbs, group them into modules, sketch interfaces, and reason about ownership. The right pane records what you have decided so far.
Task 0 of 12
Section 1: Read the requirements
Current task
Loading...
Requirements & Decisions
Read the spec below, then answer each prompt on the left.
design>
How this works: Each prompt asks for a short text answer. Tolerant matching: small variations (case, plurals, synonyms) are usually fine. Free-text prompts at the end only require a substantive response. If you get stuck, click Show hint. After two failed attempts on any task, the hint button pulses. Replays are unlimited.

Interface Design Self-Check

Eight questions on header design, module boundaries, and ownership. Pass at 70% or above; below that, take it again after reviewing.

Before you begin

Enter your name. It will appear on the score card so you can include it in your screenshot for the Lesson 23 reflection.

CS210 Lesson 23 · Interface Design Self-Check

Eight questions on header design, module boundaries, and ownership. Pass at 70% or above; below that, take it again after reviewing.
How this works: One question per card. Pick or type your answer and click Submit. Feedback appears, then click Next to move on. Answers lock once submitted, so think before you submit. After all eight, you get a score, a completion code, and a per-question recap.
6. After Class
  • Submit Lab 23 (wordle.h + DESIGN.md + main_skeleton.c) through GitHub Classroom before Lesson 24.
  • Submit the Lesson 23 reflection in Blackboard. Include the completion codes from both widgets and your screenshot.
  • Confirm your team\'s Team PEX topic proposal was submitted today. The design check-in is due at Lesson 26; today\'s lab is the rehearsal for that work at team scale.
  • Read for Lesson 24 (Git in Depth I): Beej-Git §4-6 on branching, merging, and conflict resolution.
  • Heads up: GR3 at Lesson 28 covers Block 3 content. Software design questions ARE fair game.
Need help? Schedule EI with your instructor. Bring your draft header, your DESIGN.md, and the specific design decision you are stuck on. Specific questions get unstuck quickly. The Resources section in Blackboard has the DFCS C Programming Standard, the functional decomposition reference, and the Git troubleshooting card.