Quote:Original post by Antheusis simply pointless. You didn't achieve any encapsulation, you didn't add any new information, and new functionality, you merely increased the code clutter by a factor of 10.int getFoo() const { return foo; }void setFoo(int new_foo) { foo = new_foo; }
What?!
That, by definition, *IS* encapsulation.
It allows you to change the internal functionality without changing the interface. We strictly enforce it here, and for good reason.
Today, I ended up modifying a few of these. Specifically:
Quote:had been used for months in our code. Your post would say they are unnecessary. But today, they turned in to:void SetLocked(bool flag) { mIsLocked= flag; }void SetBar(foo f) { mFoo=f; }
Quote:void SetBar(foo f) { if(mIsLocked) { mDelayedFoo = f; return; } mDelayedFoo = foo::none; mFoo = f; DoSomething(f);}void SetLocked(bool flag){ mIsLocked= flag; if(flag==false && mDelayedFoo != foo::none) { SetBar(mDelayedFoo); }}
This is *EXACTLY* the purpose of encapsulation. It reduced what would have been a multi-hour task of finding everywhere that would have modified the value directly (ewww), and dropped it down to a half-hour of figuring it out, fixing it, and testing a simple change inside the well-used interface.