Imagine you have a class with dozens of private member variables. Each member variable has a public getter and a setter function:
class Foo
{
public:
int GetA() const { return m_a; }
:
int GetZ() const { return m_z; }
void SetA(int val) { m_a = val; }
:
void SetZ(int val) { m_z = val; }
private:
int m_a;
:
int m_z
};
Now we have a second class, which is composed of Foo (amongst other things):
class Bar
{
private:
// some instances of other classes of about the same complexity as Foo
Foo m_foo;
};
So Bar is essentially a class which binds together instances of other classes in a single entity.
Functions which are passed an instance of Bar will want to access m_foo
so that they can call its getter and setter functions. Mindful of Scott Meyers advice in Effective C++ (3rd edition - item #28), I'm reluctant to add something which return a 'handle' to m_foo, e.g.
Foo& GetFoo() const { return m_foo; } // dubious const, I know
Do I have any other options though other than replicating every single getter and setter in Bar?
I'm working with some legacy code which is lazy enough to make 'm_foo' public! But this goes against some other of Scott's advice (item #22 in this case - "declare data members private").
Any way out of this bind?