Chapter 33. Name Lookup and the Interface Principle—Part 3
Take a few minutes to consider some implications of the Interface Principle on the way we reason about program design. We'll revisit a classic design problem: “What's the best way to write
There are two main ways to write
operator<<() for a class: as a free function that uses only the usual interface of the class (and possibly accessing nonpublic parts directly as a
friend), or as a free function that calls a
virtual Print() helper function in the class.
Which method is better? What are the tradeoffs?
Are you wondering why a question like this gets a title ...