You and the Document

Scribble demonstrates the MFC programming model, which separates storage of the program's data (the document) from the display of that data (the view), and from most user interaction with the data. This model supports multiple views, multiple document types, splitter windows, and other valuable user-interface features. At the heart of document/view are four key classes:

To gain a better understanding of how the document/view model works for your application, study the following tables:

This table shows how the document and other objects are created and managed in a framework application.

Key Objects in an Application


Object
Primary
purpose
Relationships to
other objects
Application Manages all other framework objects. Keeps a list of document templates.
Document template Creates and manages documents. Manages a list of open documents of a given type. Creates frame windows and views to provide a user interface for a document’s data.
Document Stores data. Manages a list of views on its data.
View Manages user interaction with a document. Attached to a document. Owned by a frame window.
Frame window Frames a view. Owns a view that is attached to a document.

This table shows your responsibilities and those of the framework in implementing a document.

Document Implementation Responsibilities

Your job The framework’s job
Derive a document class from class CDocument. Provide many document services through class CDocument.
Add data members to your class.
Implement application-specific initialization and cleanup of your document’s data. Call the appropriate initialization and cleanup functions at the right times.
Override CDocument’s Serialize member function to specify how your data is read and written. Provide implementations of File Open, Save, and Save As that call your Serialize override to read and write your data.

Typically, you also add member functions to your derived document class through which other objects — mainly the view — can access the document’s data.