I'm working with CoreData and mogenerator and trying to use the proper level of abstraction. My app deals with searching, downloading and playing different types of media files (video and audio) from different sources. Each media file has differing levels of meta-data and different ways of downloading /playing them. I've created a protocol called IMediaObject which has the minimum amount meta-data (name, author, etc..) and methods (download, play, stop, etc..) for all media files. My concrete classes will conform to this protocol and inherit from NSManagedObject, be used with CoreData, and created/modified with mogenerator.
Two questions:
Am I offtrack using a protocol for the interface here?
Should I create concrete classes for each type of media file (ITunesPodcast, VimeoVideo, TumblrMP4, etc..) for Core Data since the implementation details of these will be different? Or should I use a single MediaObject concrete class for Core Data and use properties to describe the differences between each of the media types?
Thanks in advance
Eric,
Protocols are used to publish a common set of behavior from disparate classes. Inheritance does something similar. Common modern OOP orthodoxy is to prefer to use protocols over inheritance. (Why? Inheritance is a stiff mechanism over the life cycle of an app's development and maintenance. YMMV.)
In your case, if there is little overlap of common meta-data names/behavior from each media type, then the protocol is probably your preferred path.
Andrew