I don’t think it necessarily violates encapsulation to return references to the wrapped object, particularly if they’re const. Both std::string and std::vector do this. If you can start altering the object’s internals from under it without going through its interface, that’s more questionable, but if you could already effectively do that with setters, encapsulation was an illusion anyway.
Davislor
- 1.6k
- 11
- 14