On Feb 26, 2008, at 14:36, Graham wrote:

Isn't part of the purpose of the observer mechanism to allow observees to proceed with their normal activities blissfully unaware of any observers that might be looking at 'em? In which case they won't be keeping track of their observers so have no easy way to tell them to get lost when they are about to disappear.

It's more usual, yes. In this case, no -- there's only one observer but the observees are in control.

What I'm actually doing -- or have done, rather, since it works just fine -- is implementing "fully automatic" undo by using an observer to watch all the relevant changes to the objects that make up the data model. Only the data model objects know which of their properties are relevant, so they are responsible for telling the observer what to watch and when. This is similar to what's done in the iSpend example project, but a bit more generalized.

Obviously one can design observees to keep a reference to their observers, but if they need to do that they may as well message them directly with state changes (though KVO as it stands is obviously still more convenient).

Direct messaging would mean writing code in *every* relevant setter method to support undo. Using KVO means that the data model classes need only a single registration/unregistration method that tells the observer which properties to watch. There's no other undo code in those classes whatsoever.

P.S. In case anyone remembers last week when I asked about context- sensitive undo menu strings (e.g. "Undo Create Employee" or "Undo Change Salary") I eventually found a way of doing that "fully automatically" too. But that's another story. :)

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to