5 Hide class implementations

This chapter covers

  • The importance of hiding the implementation of a class
  • The Principle of Least Knowledge
  • Lazy evaluation
  • Getter and setter functions and immutable objects
  • Rules of the Law of Demeter
  • The Open-Closed Principle

Well-designed applications incorporate proven design principles. Chapter 4 discussed the importance of loose coupling in class design. Two loosely coupled classes have minimal dependencies on each other, which helps ensure that changes in one class don’t cause changes in another class.

We can certainly be proud when other programmers admire and use the classes we wrote. But well-designed ...

Get Object-Oriented Software Design in C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.