Objectives

A language is just a collection of constructs and mechanisms. To employ a language in a proper way you need conventions or idioms describing how the constructs offered may be used to solve particular problems. This section introduces the notion of canonical classes, giving an idiomatic characterization of what is needed for the realization of abstract data types. It also presents an idiom to improve the efficiency of concrete data types.

Points to emphasize

Hints

The notion of idioms may need some explanation. You may motivate the use of idioms by referring to daily life. The ingredients constituting a canonical class may need to be repeated a number of times.

Questions

  1. What is a canonical class? Characterize its ingredients.
  2. Define a string class satisfying the requirements imposed by the canonical class idiom.
  3. Explain the handler/body idiom. Give an example.

Comments

These idioms, and the idioms presented in chapter \ref{Composition mechanisms}, merit to belong to the basic repertoire of C++ programmers, and other programmers as well. Simple examples usually work best to explain the idioms.