As jer already noted , all Objective-C methods are essentially virtual. This is a feature of the language that does not quite match other C-like languages. However, the basics of a template template can still be achieved in Objective-C, by manually forcing subclasses to implement certain functions. For example (using the convention in your related Wikipedia article):
@interface Game
{
int playersCount;
}
- (void)playOneGame:(int)numPlayers;
- (void)initializeGame;
- (void)makePlay:(int)player;
- (BOOL)endOfGame;
- (void)printWinner;
@end
@implementation Game
- (void)initializeGame { NSAssert(FALSE); }
- (void)makePlay:(int player) { NSAssert(FALSE); }
- (BOOL)endOfGame { NSAssert(FALSE); return 0; }
- (void)printWinner { NSAssert(FALSE); }
- (void)playOneGame:(int)numPlayers
{
}
@end
Game "" , . , ( ++ Java) ( Objective-C).
, playOneGame:, (*) init:
@implementation Game
...
- (void)init
{
if ((self = [super init]) == nil) { return nil; }
IMP my_imp = [Game instanceMethodForSelector:@selector(playOneGame:)];
IMP imp = [[self class] instanceMethodForSelector:@selector(playOneGame:)];
NSAssert(imp == my_imp);
return self;
}
...
@end
(*) , 100% - , playOneGame:, Objective-C instanceMethodForSelector: .