I have a class “MyCLController” with a property “dataSource” that is data source delegate for “MyCLController” class. “MyCLController” class handles location events and etc, and this class needs several methods for querying and updating several sqlite DB tables. For that reason, I have created “MyCLControlerDataSourceDelegate” protocol that declares, what methods data source delegate class should implement:
@protocol MyCLControlerDataSourceDelegate <NSObject>
@required
+ (NSArray *)getAllRegions;
+ (void)saveVisitTimeForRegionID:(NSInteger);
-(void)someInstanceMethod;
@end
And here’s the datasource delegate property declaration:
@property (nonatomic, assign) id <MyCLControlerDataSourceDelegate> dataSource;
After allocing/initing my “MyCLController”, I’m linking its dataSource property with an object of type class that implements MyCLControlerDataSourceDelegate protocol.
I would like to design “MyCLController” to be loosely-coupled, so that it doesn’t have to know what type of class “dataSource” property is. Everything is nice, when calling instance methods, for example:
[self.dataSource someInstanceMethod];
But how about calling class methods? I know that class methods should be called [ClassName classMethod] but that would make “MyCLController” less independent.
One of the solutions would be to call “class” method on an object. It will get the class name of an object and then we can call it’s class method, for example: