This chapter has introduced the basic mechanisms of object-oriented programming. We looked at a general characterization of the object model, supporting encapsulation and message passing, and observed that an object-oriented approach may reduce the complexity of the programming task but does not reduce the space and time needed to solve a problem.

The object model

1


slide: Section 2.1: The object model

In section 2, we proceeded with a fairly detailed discussion of the language constructs provided by C++, including constructors, destructors, the type modifier const and friends.

Encapsulation and inheritance in C++

2

  • encapsulation -- constructors, const, conversions, friends
  • inheritance -- abstract and concrete shapes
  • assertions -- pre- and post-conditions
Further, we looked at a simple example demonstrating how to use inheritance for defining a type hierarchy of graphical shapes. In addition, it was shown how to develop robust code by using assertions.

Canonical classes

3

  • canonical class -- constructor, destructor, assignment
  • letter/envelope -- body and handler class
In section 3, some idioms were presented which may be taken as guidelines for the implementation of concrete data types. An instance of a canonical class behaves as if it is a built-in type. To provide an efficient implementation of a concrete data type, the envelope/letter idiom may be used, in which a distinction is made between an interface handler class and an implementation body class.

Generic types

4

  • polymorphic types -- due to inheritance
  • parametrized types -- corresponding to template classes

slide: Section 2.4: Generic types

In section 4, we discussed the realization of generic types in C++. Both base class hierarchies and template classes were discussed and illustrated with examples.

Benefits and pitfalls

5

  • protection -- in relation with inheritance
  • object, pointers, references -- the sneaky example
  • inheritance -- advantages and disadvantages
  • memory management -- constructors and destructors
In section 5, we discussed some of the benefits and pitfalls of employing C++ for object-oriented programming. In particular, we discussed issues of protection, the distinction between objects, references and pointers and the pros and cons of inheritance. Further, we discussed the role of constructors and destructors in memory management.

Extensions to the object model

6

  • meta classes -- dynamic type information
  • distribution -- persistence, active objects
  • abnormal events -- exception handling

slide: Section 2.6: Extensions to the object model

Finally, we discussed a number of extensions of the basic object model, such as meta classes, carrying dynamic type information and features that are relevant for distribution, including persistence and active objects. We also discussed the issues that arise in dealing with abnormal events, which may for example occur when a pre-condition is violated.