Specialization “is-a”(C++)
- One class is a “version” of another class
- Typically subclassing or subtyping relationship
- If B is-a A, then we should be able to substitute something of type B, wherever we expect something of type A.
How is "is-a" implemented?
In C++, achieve specialization via public Inheritance.
Why Book{title, author, length}
?
Recall the 4 steps of object construction (from Constructor)
- Space is allocated
- Call the superclass constructor
- Initialize fields via a member initialization list (MIL)
- Run the constructor body
We cannot set title, author, length because they are private to book. It will use Books default constructor, won’t compile if default constructor does not exist.