Skip to main content

Posts

Showing posts from October, 2016

iOS Mid Senior level [Part 3/4]: Applying design patterns.

[1] Singleton When a class is restricted to just one instantiation, that one object is called a singleton. A singleton class returns the same instance no matter how many times an application requests it.   Example : + (instancetype)sharedManager   {      static DocumentManager * sharedDocumentManager = nil;      static dispatch_once_t onceToken;      dispatch_once(&onceToken, ^{          sharedDocumentManager = [[DocumentManager alloc] init];          NSLog(@"Singleton memory address: %@", sharedDocumentManager);      });      return sharedDocumentManager; } [2] Abstract Factory  Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Creates a base class with abstract methods defining methods for the objects that should be created. Each factory class which derives the base class can create their own implementation of each object type. Ex : Button factory produces windows butto