Mastering macOS Programming
上QQ阅读APP看书,第一时间看更新

Encapsulation

The very reason for the existence of object-oriented programming is to make programming more manageable by grouping properties and methods together in objects that are self-contained, re-usable units of code. Objects can communicate with other objects without needing to know the implementation details of those objects. Objects can contain other objects, they can be grouped together and addressed by other objects, and in an ideal world, that hierarchical relationship is straightforward and constant.

It all sounds so simple, and yet the greatest source of errors in any but the smallest of programs is complexity. This complexity is partly the result of not applying some of programming's simplest principles, or at least only applying them inconsistently.

The simplest principles of all are those that concern encapsulation. It's just so easy to forget.