Re: Newbie question: NSDocument and standard file formats
Re: Newbie question: NSDocument and standard file formats
- Subject: Re: Newbie question: NSDocument and standard file formats
- From: Erik Buck <email@hidden>
- Date: Mon, 26 Nov 2007 07:28:55 -0800 (PST)
The initialization order seems a bit weird to me - it would make sense if
you had to programmatically construct your view, but since it's all
handled for you, it seems strange that view initialisation isn't
handled first. Why is this?
The short answer is because Cocoa's document architecture is best used within an overall Model-View-Controller design. Within MVC, NSDocument is part of the Controller layer. The document's user interface is part of the View layer. What you seem to be missing in your approach is a Model layer.
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaDesignPatterns/chapter_5_section_4.html
http://developer.apple.com/documentation/Cocoa/Conceptual/AppArchitecture/Concepts/DocumentArchitecture.html
It is generally considered "bad" to store application data in user interface objects. If the only place you store your image is in an NSImageView, how will your application work if no View is presented (and therefore no nib loaded and no NSImageView created)?
The essential data of your application (in your case an image) should be stored in the Model. All operations to manipulate the data should be implemented in the Model.
Think of it this way. NSDocument must work even if no graphical View is ever displayed. Methods like readFromData:ofType:error: are intended to initialize the Model - NOT THE VIEW. In most applications, unlimited processing and data manipulation are possible within the Model even if no graphical user interface is ever shown. Think about scripts that manipulate Model data within documents.
There may be many Views that all access the same Model. There may be zero, one, or many such Views presented to a user at any time. Therefore, it is the job of the Controller layer to exchange data (in your case an image) between the Model and zero or more Views for display. You can implement the exchange of data within your NSDocument subclass or via "bindings" or in an NSWindowController subclass or in any other Controller object you find appropriate.
As an aside, thank you for this question.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden