What Classes We Design and How

By Peter Sommerlad

C++ class design has been error prone since the beginning until Scott Meyers told us about the Rule-of-Three. But even that safety rule is not enforced by the language. In addition, C++11 changed the set of compiler-provided special member functions and the intrinsic rules have become more complicated. However, instead of starting from the rules for special member functions, we will look at what role a C++ object plays and how that maps on what special member functions to define for its class and how, if any. Examples for object roles are Value, Relation, Manager (scoped, unique, general) and Subject(identity). Note, an individual object or its type can actually play several of those roles.

We will rehearse the Rule of Zero, and learn more about the Rule of Five/Six, the Rule of DesDeMovA, and the new Rule of (Unique) Three.

This all will enable you to much more consciously and safely design your class types and combine types of member variables.

As an extra we will look at relation objects that allow "Fernwirkung" in expressions and where to use relation types safely and where developer scrutiny is required to prevent undefined behavior.