Chapter 2

  1. The complexity referred to is not the structural complexity of the computation, that is the space and time needed to solve a problem, but the conceptual complexity of programming, the organization of the software. See slide 2-devices.
  2. Constructors describe what needs to be done when an instance of the class is created. Leaving the initialization of an object to the user may lead to many errors that are easily avoided by defining appropriate constructors. Destructors play a complementary role, by taking care of cleaning up before the object is destroyed.
  3. The type modifier const is used to declare a variable referring to a constant of a particular type. See slide 2-const. In addition const may be used to indicate that a member function does not affect the instance variables of an object.
  4. Automatic type conversion from a source to a target type may take place, when (a) the target type has a constructor with the source type as a single argument, or when (b) the source type defines a type operator of the target type. Type conversions may be enforced by using a cast. See slide 2-conversions.
  5. Friends may be classes or functions. They are allowed access to the private parts of an object. They may be necessary for reasons of efficiency. Friends are a relatively safe feature, since they must explicitly be declared by the class itself. They are not inherited. Neither is it possible for a class or function to declare itself as a friend of a class. Nevertheless, friends may jeopardize the integrity of an object. Treat friends with care.
  6. Generic types allow the programmer to define functionality in a general way, with respect to a variety of types. For instance, a generic container may contain items of arbitrary type. C++ supports generic types by means of inheritance and template classes. See slides slide 2-void and slide 2-template for some examples.
  7. A canonical class is a class realizing a concrete data type, that is defined to behave as a built-in type. It must include the definition of a default constructor, a copy or reference constructor, a destructor and assignment. An example is given in slide slide -2-string.
  8. The handler/body idiom describes how to separate the interface of an object class from its implementation. An example is given in slides slide 2-handler and slide 2-body.
  9. When derived classes have unlimited access to instance variables of ancestor classes, the class hierarchy defined by the inheritance relation may collapse when the implementation of an ancestor class is changed. The solution is to distinguish between private instance variables that are invisible even to derived classes and protected variables that are invisible only for external clients.
  10. This is the sneaky reference example given in slide slide 2-sneaky.
  11. Inheritance allows for an elegant conceptual organization of the class types employed in a library or program. Some potential disadvantages are listed in slide slide 2-cost.
  12. The most important extensions are meta classes, which support runtime type information, persistence, to allow for the storage of objects, and active objects, to allow for concurrency. See slide 2-extensions.