English
Summary
Conclusions
An invariant defines the valid state of an object. A constructor establishes the invariant before the object is used. Composition manages the lifetime of member values. A minimal interface makes testing easier.
Self-check questions
- How does a class differ from a particular object?
- Why should a check be performed before a data member changes?
- In what order are data members initialized?
- What happens if a constructor throws an exception?
- When is an explicit constructor needed?
- What promise does a const member function make?
- What are this and mutable for?
- How does a static data member differ from an ordinary one?
- What belongs in a header, and what belongs in a .cpp file?
- When is a struct more appropriate than an encapsulated class?
- Why can a setter for every data member make an interface worse?
- What does the created counter count in the order example?
- How do you check that a rejection leaves the state unchanged?
- Why does unique_ptr remove the need for a manual delete?
- What rules apply to designated initialization of an aggregate?