Question of style : delegates
Question of style : delegates
- Subject: Question of style : delegates
- From: Scott Thompson <email@hidden>
- Date: Thu, 01 Apr 2004 09:46:34 -0600
The delegation idom is very powerful and quite handy. Since the AppKit primarily deals with View and Controller objects I sort of had a mind set that delegates were well suited to objects in those roles.
In my own code, however, I came across a case where I think I'd like to add a delegate to a model object. I'm fairly new to this particular game and I am interested asking others (i.e. YOU) how they find that the delegate idoim works for model objects. Admittedly this is a very "idealistically" oriented topic for discussion and there are bound to be case-by-case nuances but my question is more a general one "Is the delegate model appropriate for model objects".
Here's particular case I'm working with:
My top-level model object wants to return an "undo manager" for use by the other model objects it contains. The model object is, of course, managed by an instance of NSDocument so I thought it might be nice if the top-level model object returned the undo manager that NSDocument maintains. However, this is an editing application. If used in another context (a viewer application for the same model) this model object might not have a document controller. Indeed the viewer application would not need an "undo manager" at all.
So, for this case, I thought that the top-level model object might delegate the responsibility of providing an undo manager. If the object has a delegate and that delegate chooses to provide an undo manager, then fine... the model will record its actions into that undo manager. If no undo manager is available... the model simply doesn't record it's actions (in fact, the actions that are undoable are not likely to be performed in the viewer application anyway).
Does this seem reasonable and prudent?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.