Granting functions and classes access to the non-public parts of a class with a friend declaration has been usually seen as a sign of bad design, as friendship breaks encapsulation and couples classes and functions. Friends, whether they are classes or functions, get access to all the private parts of a class, although they may only need to access parts of it. The attorney-client idiom provides a simple mechanism to restrict friends access to only designated private parts of a class.
Handling friendship with the attorney-client idiom
Getting ready
You must be familiar with how friendship is declared and how it works.
To demonstrate how to implement this idiom, we will consider the following classes: Client, which has some private member data and functions (the public...