Books / Patterns for Beginning Programmers / Chapter 14
Part III - Patterns Requiring Knowledge of Loops, Arrays, and I/O
Part III contains programming patterns that require an understanding of loops/iteration, one-dimensional arrays, and console input/output. Specifically, this part of the book contains the following programming patterns:
Reprompting. Solutions to the problem of prompting a user for input until they provide a valid response.
Accumulators. Solutions to problems that require one (or a few) “running” calculations.
Accumulator Arrays. Solutions to problems that require multiple, related “running” calculations.
Lookup Arrays. Solutions to problems that involve finding the values associated with a key, when the key has special properties.
Interval Membership. A solution to problems that involve finding the interval that contains a particular value.
Conformal Arrays. A solution to the problem of organizing multiple pieces of information that all have a common key.
Segmented Arrays. A solution to the problem of organizing multiple pieces of information of the same type.
Lookup arrays and the interval membership pattern both use arrays in less-than-obvious ways to solve problems of various kinds. They are interesting in their own right, because they help you think about novel ways to use arrays. Conformal arrays and segmented arrays are ways to organize data using arrays and then process the data using loops. They are used quite commonly in languages that don’t support object-oriented programming, and, as a result, they often find their way into programs written in object-oriented languages. They also provide an interesting contrast to objects/classes, which can also be used to solve problems of this kind.