10.4 Extensibility, Modifiability, and Reusability: Constants and Parameterization

Key Takeaways

  • Extensibility is how easily new features or cases can be added; modifiability is how easily existing behavior can be changed correctly; reusability is how easily code can be used again in other places or programs.
  • Replace a hard-coded value with a named constant or variable when it appears more than once, is likely to change, or has a meaning that the bare number hides.
  • Parameterization turns a value that is fixed inside a procedure into a parameter, so one procedure handles many cases.
  • A procedure that returns a result is more reusable than one that prints it, because callers can print, store, or combine the result.
  • Two code segments can produce identical output yet differ greatly in how easy they are to extend, modify, or reuse.
Last updated: September 2026

What this competency asks

ETS asks you to know the concepts of extensibility, modifiability, and reusability:

  1. Identify the meaning of the terms.
  2. Identify functionally equivalent statements or code segments that differ in one of these three ways.
  3. Identify situations where constants or variables would be preferred over hard-coded values.
  4. Identify opportunities for parameterization.
  5. Choose code that improves on given code by making it more extensible, modifiable, or reusable.
  6. Identify changes that would improve a given code segment.

These questions often show two segments that produce the same output and ask which is better. That makes this a design topic, not a correctness topic.

The three qualities

QualityQuestion it answersImproved by
ExtensibilityHow easily can we add a new feature or case?Data-driven designs (lists and tables instead of long if-chains), procedures, classes, inheritance
ModifiabilityHow easily can we change existing behavior without breaking it?Named constants, one place for each fact, clear names, small procedures
ReusabilityHow easily can this code be used again elsewhere?Parameters instead of fixed values, returning results instead of printing, no reliance on global variables

Constants and variables vs. hard-coded values

A hard-coded (or "magic") value is a literal written directly into the logic.

// Hard-coded
double total1 ← price1 + price1 * 0.07
double total2 ← price2 + price2 * 0.07
if ( numStudents > 30 )
    print "Class is over capacity"
end if
// Named constants
double TAX_RATE ← 0.07
int MAX_CLASS_SIZE ← 30
double total1 ← price1 + price1 * TAX_RATE
double total2 ← price2 + price2 * TAX_RATE
if ( numStudents > MAX_CLASS_SIZE )
    print "Class is over capacity"
end if

Both segments behave identically today. When the tax rate changes, however, the first version must be edited in several places, and missing one creates a bug. The second changes in one place, which improves modifiability. The names also document meaning: 30 could be anything, but MAX_CLASS_SIZE says what it is.

Prefer a named constant or a variable when the value:

  • Appears more than once
  • Is likely to change, such as rates, limits, sizes, and thresholds
  • Has a meaning the bare number hides
  • Depends on the data. Loop over n or the array's length, not a literal 10, so the code still works when the data size changes

Values such as 0 or 1 used as starting points, or the 2 in n % 2, are usually fine as literals.

Parameterization

Parameterization turns a fixed value inside a procedure into a parameter. Look for duplicated code that differs only in a value:

// Before: three near-copies
void printRowOf5Stars ( )
    for ( int i ← 0; i < 5; i ← i + 1 )
        print "*"
    end for
end printRowOf5Stars
// … and printRowOf8Stars, printRowOf10Stars …
// After: one reusable procedure
void printRow ( String symbol, int count )
    for ( int i ← 0; i < count; i ← i + 1 )
        print symbol
    end for
end printRow

Now printRow ( "*", 5 ), printRow ( "#", 8 ), and any future variation use the same tested code, which improves reusability and extensibility.

Opportunities for parameterization show up as:

  • Procedures whose names contain a specific value, such as drawSquare50 or taxForOhio
  • Copy-and-paste blocks that differ in a number or string
  • A procedure that reads a global variable that could be passed in instead

Return, don't print

// Less reusable: the procedure decides how the result is used
void showAverage ( int[ ] a, int n )
    …
    print sum / n
end showAverage

// More reusable: the caller decides
double average ( int[ ] a, int n )
    …
    return sum / n
end average

average can be printed, stored, compared, or passed to another procedure. showAverage is only good for printing. Separating computation from input and output is one of the most common "which improves the code" answers.

Designing for extension

A long chain of if tests that must be edited whenever a new case appears is hard to extend:

if ( code == "A" ) … else if ( code == "B" ) … else if ( code == "C" ) …

Storing the cases as data, for example in a dictionary that maps codes to values (Section 9.3), lets you add a case by adding an entry, without rewriting logic. In object-oriented design, adding a new subclass that overrides a method (Section 12.4) extends behavior without editing the existing classes.

Choosing the improvement

When asked which change improves a segment, look for the option that:

  1. Removes duplication, using a loop or a procedure.
  2. Replaces magic numbers with named constants or with data-derived values such as the array's length.
  3. Adds parameters so the code handles more cases.
  4. Returns values rather than printing them.
  5. Avoids global variables in favor of parameters and return values.
  6. Uses meaningful names.

Beware of choices that change the output. An "improvement" must stay functionally equivalent unless the question says the behavior should change.

Test Your Knowledge

A drawing program lets developers add a new shape type by writing one new class, without changing any existing code. Which quality does this design most directly demonstrate?

A
B
C
D
Test Your Knowledge

A program uses the literal 0.0725 in six different formulas to compute sales tax. Which change best improves the program's modifiability without changing its output?

A
B
C
D
Test Your Knowledge

A program contains three procedures, bonus10 ( ), bonus15 ( ), and bonus20 ( ), that are identical except for the percentage each adds to a score. What is the best improvement?

A
B
C
D
Test Your Knowledge

Two procedures compute the average of an array. showAverage prints the average; average returns it. Why is average generally the better design?

A
B
C
D