Insight 19.4.1.
Deciding whether to use
protected
or private
for member variables is a design decision. If you are designing a class that you expect to be extended, and you want to allow derived classes to access certain members, then protected
is appropriate. If you want to keep the implementation details hidden from derived classes, then private
is the way to go.
In this book, we will use
protected
for member variables in base classes that we expect to be extended to avoid cluttering things up with getters and setters for those variables. In a large codebase shared by many different programmers we might make a different design decision.