• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Design Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Design Question
      • From: Ken Thomases <email@hidden>
References: 
 >Design Question (From: Kaelten <email@hidden>)
 >Re: Design Question (From: Quincey Morris <email@hidden>)
 >Re: Design Question (From: Kaelten <email@hidden>)

  • Prev by Date: Re: Change Opacity of Image
  • Next by Date: Re: Core Data completely unable to find the source object model for migration
  • Previous by thread: Re: Design Question
  • Next by thread: Re: Design Question
  • Index(es):
    • Date
    • Thread