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

Design patterns

We will facilitate communication between layers of our code in such a way that those layers need to know absolutely nothing of other layers, except how to request and send data to and from each other.

In principle, truly isolated layers of an app don't even need to reside in the same building, let alone within the same app instance, on one machine. We will try to imagine that each layer has to communicate with other layers that are being written by somebody else, who has no knowledge of what we are writing ourselves.

Where possible, we will prefer to hide groups of entities behind a facade, to facilitate simpler communication with such entity groups. This allows us to split, for example, a financialReports object into several distinct and more manageable objects, such as archivedReports, pendingReports, and lastIssuedReports, without complicating the picture for the rest of the app.