On 24/06/2013, at 22:01, Graham Cox wrote:

> 
> On 25/06/2013, at 12:49 AM, Flavio Donadio <[email protected]> wrote:
> 
>> Rick Mann, I don't understand why you need a separate relationship to 
>> retrieve the active Child objects. Please, consider doing this:
>> 
>> Parent
>> children     to-many to Child
>> 
>> Child
>> parent       to-one to Parent
>> active      (boolean)
>> 
>> And then create an activeChildren: method in Parent with returns only the 
>> active children.
>> 
>> Sorry if this is not acceptable. I am just trying to help.
> 
> In my experience, this is not a good design pattern.

I did that in the past, but I wasn't constrained by Rick's requirement that 
there's only one activeChild at any given time. So, in my case, it was "good 
enough".

> It's common to want to maintain a subset of some collection (and it may be 
> that the subset can have at most a single member, as in Rick's case). Using a 
> boolean as a state variable in the objects to indicate membership of this set 
> is poor design because it a) requires a lot of management to turn off those 
> that become deselected, and b) requires much more time to iterate over the 
> collection to find the subset when needed, c) requires additional work if 
> there can be multiple, orthogonal sets of this nature.
> 
> Using the language of sets it becomes clear how to do this much more 
> efficiently: use a set! The NSSet class, and its cousin NSIndexSet, are ideal 
> for this purpose. If it's in the set it's a member, otherwise not. It's fast 
> and efficient, simple to extend without the member objects ever having to 
> care about it. Sometimes the member object will want to ask "am I a member of 
> such-and-such a set?", and this is where the child->parent relationship can 
> be used.
> 
> This is independent of Core Data, I'm not sure what features it has to 
> support this concept - maybe none, as typically this sort of subset 
> (selection) management is handled at the controller level.

CoreData requires that things be done in a very specific way, something that I 
didn't master yet... and maybe never will! So, your idea of using NSSets could 
work, but I am not able to tell.


Cheers,
Flavio
_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to