Skip to content

Instantly share code, notes, and snippets.

@onurhuseyincantay
Created January 16, 2019 13:22
Show Gist options
  • Save onurhuseyincantay/a6c5161285d00f35a6dc165066cbd93a to your computer and use it in GitHub Desktop.
Save onurhuseyincantay/a6c5161285d00f35a6dc165066cbd93a to your computer and use it in GitHub Desktop.
Class Cluster Pattern implementation example
typedef NS_ENUM (NSUInteger,PostType){
PostTypeVideo,
PostTypePhoto,
PostTypePlain,
};
@interface Post:NSObject
@property (copy) NSString *title;
@property NSDate *createdDate;
// helper for creating Post Object
+ (Post*) postWithType:(PostType)type;
- (void) animatePost;
@end
@implementation Post
+(Post*)postWithType:(PostType)type{
switch(type){
case PostTypeVideo :
return [PostVideo new];
break;
case PostTypePhoto :
return [PostPhoto new];
break;
case PostTypePlain:
return [PostPlain new];
break;
}
}
-(void) animatePost{
// Subclasses implements this
}
@end
@interface PostVideo : Post
@end
@implementation PostVideo
- (void)animatePost{
NSLog(“This is an video Animation Code!!!!")
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment