You most likely need an interface that this class can implement. I will use a human example:
@protocol PersonInterface <NSObject> @property (nonatomic, copy) NSString *firstName; @property (nonatomic, copy) NSString *lastName; @end
Class inheriting from NSObject
@interface NonManagedPerson : NSObject <PersonInterface> @end @implementation NonManagedPerson @synthesize firstName = _firstName; @synthesize lastName = _lastName; @end
Inheriting a class from NSManagedObject
@interface ManagedPerson : NSManagedObject <PersonInterface> @end @implementation ManagedPerson @dynamic firstName; @dynamic lastName; @end
Now, if an object should use any of these classes, it doesnβt matter that it supertypes it, it doesnβt matter that the object answers -firstName , -lastName , -setFirstName or -setLastName .
To provide this flexibility, you need to make sure that the objects you want to use match the interface, since you no longer worry about a particular type, for example:
@interface FootballClub : NSObject @property (nonatomic, retain) id<PersonInterface> clubManager; // .. other properties @end
Refresh
To get a general implementation, you can consider composition / delegation.
Structure
You create another class that encapsulates the overall work, and then uses it as accessible as ivar for use in your class.
Delegation
Do the same as other common elements, such as a UITableView . At certain points, it calls a datasource (any element that implements the necessary <UITableViewDatasource> methods) to ask it to do something. Then you have two objects that use the same class as the data source, and the implementation will be split.