Re: Design Question
Re: Design Question
- Subject: Re: Design Question
- From: Quincey Morris <email@hidden>
- Date: Thu, 6 Aug 2009 10:29:54 -0700
On Aug 6, 2009, at 07:46, Kaelten wrote:
I guess what I'm wondering then is how do I handle the
following case. I have several loosely coupled properties which can
read somewhat like this.
(ProjectInstall *)projectInstall {
return [ProjectInstallController
projectInstallWithProjectId:projectId];
}
And in some cases it's completely legit for the loose coupled
properties to return nil
What's the right way for this property to be KVO/KVC compliant? I
really do like bindings and believe that it's absolutely possible to
get it done right I'm just trying to figure it out.
First, I say again, *properties* aren't KVO compliant. *Objects* are
KVO compliant (or not) for each of their properties. Your question
can't be answered without knowing what class implements
'projectInstall' -- and whether 'projectInstall' is a class or
instance method, since you dropped the "+" or "-".
Assuming this is an instance method of a class named (say) Project,
which has an instance variable 'projectId', ask yourself what the
returned value depends on:
If 'projectId' changes, does that need to trigger an update of the
value of 'projectInstall' in its observers? (If not, 'projectInstall'
isn't really a property.) If so, and 'projectId' is itself a KVO-
compliant property, then you can use
setKeys:triggerChangeNotificationsForDependentKey: to set up a
dependency. If 'projectId' isn't a KVO-compliant property, you'll need
to trigger KVO notifications manually (using will/
didChangeValueForKey:@"projectInstall") *wherever* your Project class
changes the value of projectId.
Does [ProjectInstallController projectInstallWithProjectId:projectId]
always return the same value for a given value of 'projectId'? If so,
there's nothing else to do. If not, then you need to make
'projectInstall' dependent on whatever affects the value returned by
ProjectInstallController. If you can't determine that, then again
'projectInstall' isn't really a property.
I have to add that it's a bit suspicious that your 'projectInstall'
property (of a data model object) apparently has to ask a controller
object for data. (Let's hope that 'projectInstallWithProjectId:' isn't
a factory method.) It's hard to know without more context, but this
suggests your MVC design mightn't be well-formed. If that's true,
you're likely to have deeper reasons for not being able to ensure KVO
compliance.
Finally, the question of whether 'projectInstall' sometimes returns
nil is irrelevant. That has nothing to do with the compliance of the
Project object.
_______________________________________________
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