views:

39

answers:

1

I'm currently thinking about the modeling of data in an iPhone app. My first instinct is to try to normalize the data into entities.

For example a Professor entity might look something ilke this:

@interface Professor : NSManagedObject {
}

@property (nonatomic, retain) NSString * profID;
@property (nonatomic, retain) NSString * firstName;
@property (nonatomic, retain) NSString * lastName;
@property (nonatomic, retain) NSString * officeLocation;
@end

And an AvailableClass might look like this:

@interface AvailableClass : NSManagedObject {
}

@property (nonatomic, retain) NSString * className;
@property (nonatomic, retain) NSString * classAbstract;
@end

Now, we can pair the professors against the classes they teach using something like this:

@interface OfferedClass : NSManagedObject {
}

@property (nonatomic, retain) Professor * prof;
@property (nonatomic, retain) AvailableClass * classDetail;
@end
  • If I want a view which lists a catalog of all OfferedClasses (that is, there is a professor assigned to a defined class) does this mean I need multiple FetchRequestControllers and that I'll be doing multple queries in my tableView: cellForRowAtIndexPath: method?

  • It appears to me that I can create and add instances of Professor and AvailableClass, then later add instances of OfferedClass by getting values for prof and classDetail from their respective fetchedResultsController.

Am I close on any of this?

A: 

If an OfferedClass is nothing but an AvailableClass that has a Professor assigned to it, then an AvailableClass is more of an abstract thing, isn't it?

Why not make an OfferedClass a concrete subclass of AvailableClass?

Or add a Professor atttribute to a Class entity and use a predicate to test for non-nil Professor field?

There are many ways of doing this, but in the end, if the difference can be stated in a predicate, then use a predicate as a way of distinguishing the two types of classes. Then the only thing that would distinguish your two fetchedResultsControllers for the two different types of classes would be the predicate you assign the the fetchedResultsController's fetchRequest.

God of Biscuits
Well, perhaps AvailableClass has an abstract feel to it, but that's more of an artifact of my contrived example. The intention is that I have a list of one sort of item and a distinct list of another sort of item. Both of these lists are important to be able to recall.When they are linked together (by the third item) that creates a new view of the data.It seems to me that adding a Professor attribute to the Class field requires me to repeat instances of a specific Class item if more than one professor teaches that class. In that case, we have an update anomaly on the Class data, right?
MrAleGuy