iOS design mode-templates
Schematic diagram
Description
Defines the skeleton of an algorithm in an operation, and defers the step to the subclass. The template method allows subclasses to redefine some specific steps of an algorithm without altering the structure of an algorithm.
Source
Https://github.com/YouXianMing/TemplatePattern
////GameProtocol.h//Templatepattern////Created by youxianming on 15/10/27.//copyright©2015 year Zipeiyi. All rights reserved.//#import<Foundation/Foundation.h>@protocolGameprotocol <NSObject>@required/** * Set Number of players * * @param count*/- (void) Setplayercount: (int) count;/** * Returns the number of players * * @return number of players*/- (int) Playercount;/** * Initialize game*/- (void) Initializegame;/** * Start the game*/- (void) Makeplay;/** * End the game*/- (void) Endofgame;@end
// // Monopoly.h// templatepattern//// Created by Youxianming on 15/10/27. // copyright©2015 year Zipeiyi. All rights reserved. // #import <Foundation/Foundation.h>#import"GameProtocol.h" @interface monopoly:nsobject <GameProtocol>@end
////monopoly.m//Templatepattern////Created by youxianming on 15/10/27.//copyright©2015 year Zipeiyi. All rights reserved.//#import "Monopoly.h"@interfaceMonopoly () @property (nonatomic, assign)intGameplayercount;@end@implementationMonopoly- (void) Setplayercount: (int) Count {self.gameplayercount=count;}- (int) Playercount {returnSelf.gameplayercount;}- (void) initializegame {NSLog (@"Monopoly Initialize");}- (void) Makeplay {NSLog (@"Monopoly Makeplay");}- (void) endofgame {NSLog (@"Monopoly Endofgame");}@end
// // Chess.h// templatepattern//// Created by Youxianming on 15/10/27. // copyright©2015 year Zipeiyi. All rights reserved. // #import <Foundation/Foundation.h>#import"GameProtocol.h" @interface chess:nsobject <GameProtocol>@end
////CHESS.M//Templatepattern////Created by youxianming on 15/10/27.//copyright©2015 year Zipeiyi. All rights reserved.//#import "Chess.h"@interfaceChess () @property (nonatomic, assign)intGameplayercount;@end@implementationChess- (void) Setplayercount: (int) Count {self.gameplayercount=count;}- (int) Playercount {returnSelf.gameplayercount;}- (void) initializegame {NSLog (@"Chess Initialize");}- (void) Makeplay {NSLog (@"Chess Makeplay");}- (void) endofgame {NSLog (@"Chess Endofgame");}@end
Details
iOS design mode-templates