If your class contains an object that can be used by others, expose it. Encapsulation is designed to hide the variables needed for something. Some data members do not fall into this.
Example:
Volume man;
tom.getEyes().getColor(); tom.getMouth().eat(tomato); tom.legs().walk();
A person could hide everything, but that would be cumbersome:
tom.getEyesColor(); // accessor for every eye feature tom.eat(tomato); tom.walkAndEat(); // every possible combination of actions
Further example:
grid.row(3).col(5).setText("hello");
Here a column class can expose many methods without the need for a grid class. This is the beauty of object-oriented programming.
If you named your class ObjectManager, I realized that it manages the object instances for others, so you have to expose it. Another idea to use inheritance is also valid:
class ObjectManager : public Object { };
source share