Can you explain the Document-View architecture in MFC ?
The document view architecture was introduced in MFC 2.0. In this architecture the application’s data is represented as a “document” object and the views of this data are represented as “view” objects. E.g. If you create an excel document what you see to get your job done i.e. cells, values, etc comprises the view and when you save this data it gets saved as a document. The various views of this document is as a table, graphs, bar charts, etc.
The data is stored in a document object. The class representing the document object is CDocument. The sole purpose of this class is to manage an application’s data.
Views server two purposes: renders visual representation of data stored in document and translate the user’s inputs into commands that operate on the data in the document. The class for view is CView. Thus the division of work in terms of data and view helps in work division, better productivity and reusability of code.
There are two types of document/view applications:
- SDI (Single Document Interface): This supports just a single open document at a time.
E.g. Wordpad, Notepad. If the user wants to open multiple documents then he has to open multiple instances of wordpad/notepad.
- MDI (Multiple Document Interface): Supports multiple documents and multiple views of a document. An application is MDI if the user can open multiple documents in the same application instance.
E.g. Microsoft Word: The user can open multiple documents within a single instance of Ms Word.
