Concepts / Problem Analysis and Decomposition

Problem Analysis and Decomposition

Specifying program requirements means translating a vague problem into concrete, measurable specifications that leave no room for ambiguity.

  • Programming

From Goal to Specification

A programming problem often begins as a broad goal: create a backup system, build a calculator, or organize data. A goal describes the desired outcome, but it does not yet tell a program exactly what to do. Problem analysis begins by replacing that general intention with requirements that are concrete, measurable, and unambiguous.

For a backup program, the specification must settle four decisions: which files will be backed up, where the backup will be stored, which archive format will be used, and how the archive will be named. These decisions form the bridge between understanding the problem and designing its implementation.

Backup systemFiles to back upMain backup directoryZip archive formatCurrent date and timedecomposedecomposedecomposedecompose
What changes when a general backup intention is decomposed into specific decisions?

The Four Backup Decisions

A complete backup specification has four distinct components. Each one answers a different question about the backup process. Together, they define what the program must archive, where it must put the result, what form that result must take, and what name the result must receive.

Backupspecificationcomplete requirementsFilesa list to back upStorage locationmain backup directoryArchive formatzipNaming schemecurrent date and timedefinesdefinesdefinesdefines
What four requirement areas must be defined to fully specify a backup program?
Requirement areaWhat it determinesSpecified form
Files to back upThe input content for the backupA list of files
Storage locationWhere the archive will be writtenA main backup directory
Archive formatThe form of the resulting archiveZip
Naming schemeWhat identifies the resulting archiveThe current date and time

The four decisions that make a backup specification complete

A Worked Backup Specification

Worked example

Decomposing a General Backup Goal

Turn the general goal "create a backup system" into a complete specification.

  1. 1
    Identify the files

    State the files to back up as a concrete list rather than leaving the program to guess what belongs in the backup.

  2. 2
    Identify the location

    Specify the main backup directory so the program has a defined place to write the archive.

  3. 3
    Identify the format

    Choose the archive format. The standard specification uses zip.

  4. 4
    Identify the name

    Define a naming scheme based on the current date and time so the archive naming rule is explicit.

Result

The vague goal has become a four-part specification: a file list, a main backup directory, the zip format, and a current-date-and-time naming scheme.

The example does not yet implement the backup. It establishes the contract that an implementation must satisfy. This distinction is important: analysis and decomposition happen before code, and their output is a blueprint for the design phase.

Choosing the Archiving Tool

After the backup requirements are defined, the program still needs a tool that creates the archive. An archiving command reads files and writes them into a compressed archive. The key selection requirement is that the tool must support invocation from the command line.

zipstandard choiceArchiving commandmust run from command lineOther archivercommand line interfacesatisfiesmay satisfy
How do the backup requirements constrain the archiving command while leaving the specific tool flexible?
ChoiceStatusReason
zipAcceptable and standardIt is available by default in a standard GNU/Linux or Unix distribution and supports command line invocation.
tarAcceptable if command-line capableThe requirement allows any command line archiving tool.
7zAcceptable if command-line capableThe requirement allows any command line archiving tool.
rarAcceptable if command-line capableThe requirement allows any command line archiving tool.

The tool is flexible; command line invocation is the required criterion.

When Requirements Are Incomplete

  • Common mistake

    Listing files and a destination but omitting the naming scheme

    What it looks like

    The specification says what to back up and where to store it, but does not say what to call the archive.

    Why it fails

    The program does not have a complete rule for identifying the resulting archive.

    Do this instead

    Define a naming scheme based on the current date and time.

  • Common mistake

    Defining files and a format but omitting the storage directory

    What it looks like

    The specification says to create a zip archive from a file list but does not identify a main backup directory.

    Why it fails

    The program has no specified place to write the backup.

    Do this instead

    Specify the main backup directory.

  • Common mistake

    Treating the general goal as if it were already an implementation plan

    What it looks like

    The instruction is simply to create a backup system.

    Why it fails

    A broad goal does not identify the files, location, format, or naming scheme that the implementation must follow.

    Do this instead

    Decompose the goal into the four required components.

  • Common mistake

    Selecting a tool without checking command-line support

    What it looks like

    A tool is chosen without establishing that it can be invoked from the command line.

    Why it fails

    Command-line invocation is the required criterion for the archiving command.

    Do this instead

    Choose zip or another archiving tool that supports command-line invocation.

The Specification as a Contract

A finished specification is a contract between the problem and the solution. It answers the question, "What must the program do?" For the backup problem, the specification state is reached only when the file list, storage directory, archive format, and naming scheme have all been decided.

This contract improves implementation because it gives the code a clear target. An incomplete or ambiguous specification leads to an incomplete or ambiguous implementation. A clear specification reduces misunderstandings and rework, and makes the coding phase more reliable.

EASY

A backup requirement currently says only: "Make a backup of the project." Decompose this statement into the four requirement areas that must be settled before implementation.

Hints
  • Ask what exact input content the backup should contain.
  • Ask where the archive should be written.
  • Ask what archive format is required.
  • Ask how the resulting archive should be named.
  • Files to back up: define a concrete list.
  • Storage location: define the main backup directory.
  • Archive format: define zip as the standard format in this specification.
  • Naming scheme: define the current date and time.

Key Takeaways

  • Problem analysis translates a vague programming goal into concrete, measurable, and unambiguous requirements.
  • A complete backup specification defines the files, storage location, archive format, and naming scheme.
  • Every one of the four components is necessary; omitting one leaves implementation-critical information unresolved.
  • The archiving command is flexible, but it must support command-line invocation; zip is the standard choice.
  • A complete specification acts as a blueprint and contract for the implementation.

Related concepts

More concepts starting with P