Container classes

  1. classes that contain collections of other objects
  2. implements data structures
  3. heterogenous or homogenous
  4. reference semantics or value semantics
  5. In C++ use templates.

Common problem: code duplication solutions:

  1. Have a common base class for templates. All methods that don't reference parameter are promoted to base class.
  2. Wrapper Class: Define generic container class using void* or base_elem*, for example: stack tex2html_wrap78 void * tex2html_wrap79 . Wrapper class is base class of templated container. For example: template tex2html_wrap78 class stack_elem tex2html_wrap79 stk::private stack tex2html_wrap78 void * tex2html_wrap79 {}. Methods are inline calls to base methods with a type cast. Much more code reuse. Problems: dangerous casts and reference semantics only.




source
psfile jl@crush.caltech.edu index
wrapper_class