On Jan 19, 2012, at 1:33 , Ken Thomases wrote:
> On Jan 18, 2012, at 6:12 PM, Marcel Weiher wrote:
>> On Jan 14, 2012, at 18:37 , Kyle Sluder wrote:
>> 
>>> Breaking this pattern should be a conscious decision.
>> 
>> I'd say that the opposite is true:  in general you should avoid specific 
>> model -> view communication as per MVC (apart from invalidation), but in 
>> specialized and very simple cases you may be able to get away with it.
> 
> KVO and bindings are not "specific model -> view communication", they are a 
> generalized mechanism which avoid coupling.  The model just supports a 
> generalized observer pattern.  It doesn't know anything about its observers; 
> it doesn't even know or care whether there are any.

Hi Ken!

I have to admit that my thoughts on this are not 100% formed yet, but while I 
agree with you in theory, my observations from practice (mostly looking at code 
provided by people who work(ed) for me) are that this happy theory doesn't pan 
out in practice.

What I see in KVO and NSNotification code is that instead of noting what has 
changed, the code immediately acts on that notification, usually by updating 
the UI.   What you then have is not decoupled code, but coupled code (with at 
least temporal coupling) where the coupling is implicit rather than explicit.  
To me, implicitly coupled code is actually worse than explicitly coupled code 
(with actually decoupled code better than either).

That's a fairly high-level wishy-washy type of information, and only my 
experience, though a very consistent experience.

I think another bit that contributes to this problem is that both KVO and 
NSNotification call clients directly, rather than going through a queue that 
could, for example, be used for event coalescing.  Because they are called 
directly, the effect is really very close to inserting a message-send right 
where you send the notification, and typically there is often only one or at 
most a couple of potential listeners for that notification, so you might as 
well just put in a delegate and make the dependency explicit (again assuming my 
valuation of implicit coupling as worse than explicit coupling is true).  

Your mileage may vary,

Marcel


_______________________________________________

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

This email sent to arch...@mail-archive.com

Reply via email to