So, I just read through Item 31 in Effective C++ and it confused the hell out of me. The idea is to minimize compilation on the client's part and I get why it's desirable, but I just don't see how it's possible. In order for code to run it needs to be compiled, right? And therefore if you change anything pertaining to it, it needs to be compiled again. There's no way the changes would show up unless they are made at runtime. One part that confused me in particular was his use of the pimpl idiom to separate the interface and the implementation:
Code:
#include <string>
#include <memory>
class PersonImpl;
class Date;
class Address;
class Person {
public:
Person(const std::string& name, const Date& birthday, const Address& addr);
std::string name() const;
std::string birthDate() const;
std::string address() const;
…
private:
std::tr1::shared_ptr<PersonImpl> pImpl;
};
And this is the explanation that follows:
"Here, the main class contains as a data member nothing but a pointer to its implementation class.
With this design, clients of Person are divorced from the details of dates, addresses, and persons. The implementations of those classes can be modified at will, but Person clients need not recompile."
I don't understand that. Why would they not need to recompile if the implementation has been changed? If he is talking about changes at runtime, can't you also modify the data members through member functions at runtime with no need to compile? I really have no idea what he's talking about.