Previous section   Next section

Imperfect C++ Practical Solutions for Real-Life Programming
By Matthew Wilson
Table of Contents
Chapter 3.  Resource Encapsulation


3.1. A Taxonomy of Resource Encapsulation

The classic texts [Stro1997] discuss resource encapsulation in terms of the Resource Acquisition Is Initialization (RAII) mechanism (see section 3.5). However, as with so many things in software engineering, there are several levels of resource encapsulation. The most basic level of resource encapsulation is, of course, no encapsulation at all. Beyond that, we need to consider the services that resource encapsulation provides

  • Automatic acquisition of resource(s)

  • Convenient interface for manipulation of resource(s)

  • Automatic release of resource(s)

Given this list, we can postulate the following taxonomy of resource encapsulation:

  1. No encapsulation

  2. POD types (section 3.2)

  3. Wrapper proxies (section 3.3)

  4. RRID types (section 3.4)

  5. RAII types (section 3.5)

We're going to use a couple of examples to take us through the journey into this concept in this chapter. Before we get into it, I should tell you that this chapter and the next took more thinking time (vs. writing time) than any others in the book. That's not because they're terribly complicated concepts, rather because the two concepts are so very similar that attempting to delineate cleanly between them was challenging, to say the least. As a consequence, you may find some of the examples in these chapters a bit contrived, but I ask you to bear with it and understand that the focus is on separating the concepts clearly.


      Previous section   Next section