Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data design question




On May 3, 2005, at 10:16 AM, John Timmer wrote:
I've got a series of NSManagedObjects and subclasses. Most of them have a
"notes" field holding RTF saved as NSData. I'd like to expose the text of
these notes to being searched by adding a method that makes an attributed
string out of the data and then extracts the raw string. The question is:
where do I put this method? I could:
Add a category to NSManagedObject with a "searchableNotes" method and trap
exceptions for when the "notes" key doesn't exist.


This doesn't really encapsulate application logic. (And...)

Assume that the "searchableNotes" method won't change, and just add it in to
any classes that need it.


This doesn't use the benefits of object orientation. (And...)

Subclass NSManagedObject, add the "searchableNotes" method, and make all the
objects with a "notes" key subclasses of this.


This approach is just right...

You might also consider defining an *entity* (probably abstract) from which the other entities inherit -- it would contain a searchableNotes attribute.


Depending on likely access patterns, you might also consider caching the searchableNotes. See <http://developer.apple.com/documentation/ Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html> for details of an approach to implementing this.


mmalc

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Core Data design question (From: John Timmer <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.