Has anybody gone through Item 20 of Scott Meyers: 50 Specific Ways? In that item, he tries to give two specific advantages of declaring data members in private interface rather than public.
Towards the end of the item, he states: "a valuable source of flexibility that you wouldn't have if you made a decision to include the running average data member in the public interface"
Why does he say so? Even if the running average data member is in the public interface, the averageSoFar() function could still access it, and the flexibility still exists. You might have to refer the book, to answer this.
Because the public interface is what the end-user has access to. Consider that example as a popular library, maybe released online and downloaded by a number of users. In the next version of library, if it was decided to change the implementation it still should not change/remove that data member because there could be client code that relies on it. As an end-user of a library, you would not expect upgrading to the latest version of a library to break your code!
Thanks Seymore, but what you're trying to explain is different.
Let me rephrase - What is the distinctive advantage of declaring running_average data member in private as opposed to public interface, in this particular example
He says there are couple of ways that the private member can be accessed by public functions, but my point is, the same variable can be accessessed by the same public functions, even if it was in the public interface.