Chapter 11. Cocoa’s Multiple-Document Architecture

Document-based applications are one of the more common types of applications developed today. They provide a framework for generating identically contained, but uniquely composed, sets of data that can be stored in files. Word processors and spreadsheet applications are two well-known examples of document-based applications. Before investigating how document-based applications are structured, let’s consider exactly what such an application does. It:

  • Creates new documents

  • Opens existing documents that are stored in files

  • Saves documents under user-designated names and locations

  • Reverts to saved documents

  • Closes documents (usually after prompting the user to save changes)

  • Prints documents and allows the page layout to be modified

  • Represents data of different types internally

  • Monitors and sets the document’s edited status and validates menu items

  • Manages document windows, including setting the window titles

  • Handles application and window delegation methods (such as when the application terminates)

Cocoa’s remarkable multiple-document architecture consists of a set of three classes—NSDocument, NSDocumentController, and NSWindowController—which provide the features in the preceding list almost entirely “for free.” Using the multiple-document architecture drastically simplifies the work developers must do to implement a multidocument application. Once you understand how the architecture works, you can have a multidocument application up and ...

Get Learning Cocoa now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.