= Solution
<Encapsulation> exposes operations with contracts while hiding representation details and controlling changes to state. In a text editor, a document object can privately store text and cursor position and expose `insert`, `delete` and `moveCursor`. Clients cannot directly splice internal storage or set a cursor outside the document. \b[The document's methods enforce its <representation invariant>], and the implementation can later replace a character <array> by a different text representation without changing the public editing interface. Merely declaring a field private is insufficient if an accessor returns the mutable representation itself.
Back to article page