In order to keep encapsulation, I need to write getter and setters instead of returning the member variable as a reference, |
This is the wrong mentality. Very wrong.
Getters/setters are terrible. They are bad for encapsulation. Granted... they're not
as bad as public members... but they're still bad.
Classes function better when they are a singular entity... and not just a collection of a bunch of different parts. Getters/setters destroy that singular entity idea and instead pull out a small part of the class -- which breaks encapsulation.
Ideally... if a class is properly encapsulated... outside code
shouldn't even know or care what pieces belong to your class.
As with any design question, it is difficult to give a straight answer, since the best way to design something depends a lot on what you're trying to do. So I can't really say what would be the best thing for you in this specific instance.
What I
will say, though... is that there is extremely little (if any) value in making variables private if you are just going to write a bunch of getters/setters for all of them. That's nothing but a waste of time.