SlideShare a Scribd company logo
Design Patterns 
in Cocoa Touch 
Eliah Snakin
Design Pattern 
a general 
reusable 
solution to a 
commonly 
occurring 
problem within 
a given context 
GoF
View Controller Model 
MVC
MVC Communication Diagram 
Controller 
Notify 
Update 
Update 
Events 
Model View
MVC as a Compound Design 
Pattern 
Strategy Mediator Observer 
Composite Command
MVC as a Compound Design 
Pattern 
Controller 
Notify 
Update 
Update 
Events 
Composite 
Model View 
Command 
Mediator 
Observer 
Strategy
Program to an 
interface, 
not an 
implementation 
?
Delegation 
A mechanism by which a host object embeds a weak 
reference to another object—its delegate—and periodically 
sends messages to the delegate when it requires its input 
Template 
Method 
Decorator 
Adapter 
for a task.
Catalogue patterns in 
Cocoa Touch 
Prototype 
Factory 
Method 
Abstract 
Factory 
Builder Singleton 
Adapter Bridge Façade Mediator Observer 
Composite Iterator Visitor Decorator 
Chain of 
Responsibility 
Template 
Method 
Strategy Command Flyweight Proxy
Prototype Creational 
GoF:! 
Specify the kinds of objects to create using a prototypical instance and 
create new objects by coping the prototype. 
Cocoa Touch Example:! 
Prototype cells in UITableView 
Use dynamic prototypes to design one cell and then use it as the 
template for other cells in the table. Use a dynamic prototype 
when multiple cells in a table should use the same layout to 
display information. 
- tableView:cellForRowAtIndexPath: 
- dequeueReusableCellWithIdentifier:
Abstract Factory Creational 
GoF:! 
Provide an interface for creating families of related or dependent objects 
without specifying their concrete classes. 
Cocoa Touch Example:! 
The interface declared by the abstract superclass, NSNumber 
(Class cluster) 
Class clusters group a number of private concrete subclasses 
under a public abstract superclass.
Class cluster 
Class clusters group a number of private concrete subclasses 
under a public abstract superclass. 
The abstract superclass handles instantiation 
NSNumber *aChar = [NSNumber numberWithChar:’a’]; 
NSNumber *anInt = [NSNumber numberWithInt:1]; 
Each object returned by the factory methods belong to a 
different private subclass which is hidden to users. 
Apple Documentation
Class clusters with Multiple 
Public Superclasses 
Apple Documentation
Factory Method Creational 
GoF:! 
Define an interface for creating an object, but let subclasses decide which 
class to instantiate. 
Cocoa Touch Example:! 
Convenience class-methods, returning instances. 
NSNumber 
+ numberWithBool: 
+ numberWithChar: 
…
Singleton Creational 
GoF:! 
Ensure a class only has one instance, and provide a global point of 
access to it. 
Cocoa Touch Example:! 
UIApplication, UIAccelerometer … 
UIApplication *applicationSingleton = [UIApplication 
sharedApplication]; 
! 
UIAccelerometer *accelerometerSingleton = 
[UIAccelerometer sharedAccelerometer];
Singleton 
+ (id)sharedManager { 
static MyManager *sharedMyManager = nil; 
static dispatch_once_t onceToken; 
dispatch_once(&onceToken, ^{ 
sharedMyManager = [[self alloc] init]; 
}); 
return sharedMyManager; 
} 
http://www.galloway.me.uk/tutorials/singleton-classes/
Adapter Interface adaptation 
GoF:! 
Converts the interface of a class into another interface clients 
expect. Adapter lets classes work together that couldn’t otherwise 
because of incompatible interfaces. 
Cocoa Touch Example:! 
Delegation — mix of Adapter, Decorator, Template Method 
Uses Protocol or Block 
You should always use a class’s delegation mechanism instead 
of subclassing the class, unless the delegation methods do not 
allow you to accomplish your goal.
Façade Interface adaptation 
GoF:! 
Provides a unified interface to a set of interfaces in a system. 
Façade defines a higher-level interface that makes the subsystem 
easier to use. 
Cocoa Touch Example:! 
NSImage provides a unified interface for loading and using images that 
can be bitmap-based (such as those in JPEG, PNG, or TIFF format) or 
vector-based (such as those in EPS or PDF format).
Mediator Decoupling 
GoF:! 
Defines an object that encapsulates how a set of objects interacts. 
Mediator promotes loose coupling by keeping objects from referring 
to each other explicitly, and it lets you vary their interaction 
independently. 
Cocoa Touch Example:! 
UIViewController 
AppKit implements the NSController class and its 
subclasses. These classes and the bindings 
technology are not available in iOS.
Observer Decoupling 
GoF:! 
Defines a one-to-many dependency between objects so that when 
one object changes state, all its dependents are notified and 
updated automatically. 
Cocoa Touch Example:! 
NSNotification, Key-Value Observing 
Notifications KVO 
A central object that provides 
change notifications for all 
observers 
The observed object directly 
transmits notifications to observers. 
Mainly concerned with program 
events in a broad sense 
Tied to the values of specific object 
properties
Composite Abstract collection 
GoF:! 
Compose objects into tree structures to represent part-whole hierarchies. 
Composite lets clients treat individual objects and compositions of objects 
uniformly. 
Cocoa Touch Example:! 
View Hierarchy — structural architecture that plays a part in both 
drawing and event handling.
Iterator Abstract collection 
GoF:! 
Provide a way to access to the elements of an aggregate object sequentially 
without exposing its underlying representation. 
Cocoa Touch Example:! 
NSEnumerator 
NSEnumerator *itemEnumerator = [anArray objectEnumerator]; 
NSString *item; 
while (item = [itemEnumerator nextObject]) { } 
Block-Based Enumeration 
! 
Fast Enumeration 
! 
Internal Enumeration 
[anArray enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {}]; 
for (NSString * item in anArray) {} 
- (void)makeObjectsPerformSelector:(SEL)aSelector
Decorator Behavioural 
GoF:! 
Attaches additional responsibilities to an object dynamically. Decorators 
provide a flexible alternative to subclassing for extending functionality. 
Cocoa Touch Example:! 
NSAttributedString, NSScrollView, and UIDatePicker 
Implemented with True Subclasses or Categories.
Chain of Responsibility Behavioural 
GoF:! 
To avoid coupling the sender of a request to its receiver by giving 
more than one object a chance to handle the request. It chains the 
receiving objects and passes the request along the chain until an 
object handles it. 
Cocoa Touch Example:! 
UIResponder 
If a view is managed by a UIViewController object, the 
view controller becomes the next responder in the chain 
(and from there the event or action message passes to 
the view’s superview).
Template Method Algorithm Encapsulation 
GoF:! 
Define the skeleton of an algorithm in an operation, deferring some 
steps to subclasses. Template Method lets subclasses redefine 
certain steps of an algorithm without changing the algorithm's 
structure. 
The Template Method pattern is a fundamental design of Cocoa, and 
indeed of object-oriented frameworks in general. 
The pattern in Cocoa lets custom components of a 
program hook themselves into an algorithm, but the 
framework components determine when and how they 
are needed.
Strategy Algorithm Encapsulation 
GoF:! 
Define a family of algorithms, encapsulate each one, and make 
them interchangeable. Strategy lets the algorithm vary 
independently from clients that use it. 
Cocoa Touch Example:! 
a controller determines the behavior of a view about what and when to 
display the data from a model. The view itself knows how to draw 
something but doesn’t know what until the controller tells it what to 
display.
Command Algorithm Encapsulation 
GoF:! 
Encapsulate a request as an object, thereby letting you 
parameterize clients with different requests, queue or log requests, 
and support undoable operations. 
Cocoa Touch Example:! 
NSInvocation, somewhat a target-action mechanism of Cocoa
Happy Coding :)

More Related Content

What's hot

Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
Lalit Kale
 
Model Manipulation Using Embedded DSLs in Scala
Model Manipulation Using Embedded DSLs in ScalaModel Manipulation Using Embedded DSLs in Scala
Model Manipulation Using Embedded DSLs in Scala
Filip Krikava
 
A Recommender System for Refining Ekeko/X Transformation
A Recommender System for Refining Ekeko/X TransformationA Recommender System for Refining Ekeko/X Transformation
A Recommender System for Refining Ekeko/X Transformation
Coen De Roover
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
Abhijit Gaikwad
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
Ganesh Kolhe
 
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
Coen De Roover
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Kavitha713564
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
Naga Muruga
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design Patterns
Michael Heron
 
PATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsPATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design Patterns
Michael Heron
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Satheesh Sukumaran
 
Enriching EMF Models with Scala (quick overview)
Enriching EMF Models with Scala (quick overview)Enriching EMF Models with Scala (quick overview)
Enriching EMF Models with Scala (quick overview)
Filip Krikava
 
20111115 e trice eclipse demo camp munich
20111115 e trice eclipse demo camp munich20111115 e trice eclipse demo camp munich
20111115 e trice eclipse demo camp munich
tschuetz
 
Java beans
Java beansJava beans
13 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_1913 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_19
Niit Care
 
06 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_0806 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_08
Niit Care
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
Jamie (Taka) Wang
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
relay12
 

What's hot (18)

Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
Model Manipulation Using Embedded DSLs in Scala
Model Manipulation Using Embedded DSLs in ScalaModel Manipulation Using Embedded DSLs in Scala
Model Manipulation Using Embedded DSLs in Scala
 
A Recommender System for Refining Ekeko/X Transformation
A Recommender System for Refining Ekeko/X TransformationA Recommender System for Refining Ekeko/X Transformation
A Recommender System for Refining Ekeko/X Transformation
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design Pattern
 
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
A Logic Meta-Programming Foundation for Example-Driven Pattern Detection in O...
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design Patterns
 
PATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsPATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Enriching EMF Models with Scala (quick overview)
Enriching EMF Models with Scala (quick overview)Enriching EMF Models with Scala (quick overview)
Enriching EMF Models with Scala (quick overview)
 
20111115 e trice eclipse demo camp munich
20111115 e trice eclipse demo camp munich20111115 e trice eclipse demo camp munich
20111115 e trice eclipse demo camp munich
 
Java beans
Java beansJava beans
Java beans
 
13 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_1913 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_19
 
06 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_0806 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_08
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 

Viewers also liked

Design patterns
Design patternsDesign patterns
Design patterns
ISsoft
 
Factory Pattern
Factory PatternFactory Pattern
Factory Pattern
Monjurul Habib
 
Design patterns - Abstract Factory Pattern
Design patterns  - Abstract Factory PatternDesign patterns  - Abstract Factory Pattern
Design patterns - Abstract Factory Pattern
Annamalai Chockalingam
 
Design Pattern - 2. Observer
Design Pattern -  2. ObserverDesign Pattern -  2. Observer
Design Pattern - 2. Observer
Francesco Ierna
 
The Observer Pattern (Definition using UML)
The Observer Pattern (Definition using UML)The Observer Pattern (Definition using UML)
The Observer Pattern (Definition using UML)
John Ortiz
 
Observer pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expressionObserver pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expressionLearningTech
 
Observer & singleton pattern
Observer  & singleton patternObserver  & singleton pattern
Observer & singleton pattern
babak danyal
 
Observer pattern
Observer patternObserver pattern
Observer pattern
Somenath Mukhopadhyay
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Srikrishnan Suresh
 
Observer pattern
Observer patternObserver pattern
Observer pattern
Shahriar Iqbal Chowdhury
 
Observer Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 AugObserver Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 Aug
melbournepatterns
 
Design patterns 4 - observer pattern
Design patterns   4 - observer patternDesign patterns   4 - observer pattern
Design patterns 4 - observer pattern
pixelblend
 
Design patterns: observer pattern
Design patterns: observer patternDesign patterns: observer pattern
Design patterns: observer pattern
Jyaasa Technologies
 
Reflective portfolio
Reflective portfolioReflective portfolio
Reflective portfolio
jobbo1
 
Design patterns - Observer Pattern
Design patterns - Observer PatternDesign patterns - Observer Pattern
Design patterns - Observer Pattern
Annamalai Chockalingam
 
Design Pattern - Observer Pattern
Design Pattern - Observer PatternDesign Pattern - Observer Pattern
Design Pattern - Observer Pattern
Mudasir Qazi
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
Sara Torkey
 
Observer Pattern
Observer PatternObserver Pattern
Observer Pattern
Akshat Vig
 
Observer pattern
Observer patternObserver pattern
Observer pattern
Samreen Farooq
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
Sameer Rathoud
 

Viewers also liked (20)

Design patterns
Design patternsDesign patterns
Design patterns
 
Factory Pattern
Factory PatternFactory Pattern
Factory Pattern
 
Design patterns - Abstract Factory Pattern
Design patterns  - Abstract Factory PatternDesign patterns  - Abstract Factory Pattern
Design patterns - Abstract Factory Pattern
 
Design Pattern - 2. Observer
Design Pattern -  2. ObserverDesign Pattern -  2. Observer
Design Pattern - 2. Observer
 
The Observer Pattern (Definition using UML)
The Observer Pattern (Definition using UML)The Observer Pattern (Definition using UML)
The Observer Pattern (Definition using UML)
 
Observer pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expressionObserver pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expression
 
Observer & singleton pattern
Observer  & singleton patternObserver  & singleton pattern
Observer & singleton pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Observer Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 AugObserver Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 Aug
 
Design patterns 4 - observer pattern
Design patterns   4 - observer patternDesign patterns   4 - observer pattern
Design patterns 4 - observer pattern
 
Design patterns: observer pattern
Design patterns: observer patternDesign patterns: observer pattern
Design patterns: observer pattern
 
Reflective portfolio
Reflective portfolioReflective portfolio
Reflective portfolio
 
Design patterns - Observer Pattern
Design patterns - Observer PatternDesign patterns - Observer Pattern
Design patterns - Observer Pattern
 
Design Pattern - Observer Pattern
Design Pattern - Observer PatternDesign Pattern - Observer Pattern
Design Pattern - Observer Pattern
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Observer Pattern
Observer PatternObserver Pattern
Observer Pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 

Similar to Design Patterns in Cocoa Touch

Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
Nishith Shukla
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
pradeepkothiyal
 
Design patterns
Design patternsDesign patterns
Design patterns
Anas Alpure
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
Srikanth R Vaka
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.ppt
MsRAMYACSE
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
Shahzad
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Luis Valencia
 
Design patterns in brief
Design patterns in briefDesign patterns in brief
Design patterns in brief
DUONG Trong Tan
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Rafael Coutinho
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of Patterns
Chris Eargle
 
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Steven Smith
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
Ivano Malavolta
 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una Daly
Una Daly
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
Amr Elghadban (AmrAngry)
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.ppt
bryafaissal
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.ppt
AnkitPangasa1
 
Lezione 03 Introduzione a react
Lezione 03   Introduzione a reactLezione 03   Introduzione a react
Lezione 03 Introduzione a react
University of Catania
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
Jason Townsend, MBA
 

Similar to Design Patterns in Cocoa Touch (20)

Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.ppt
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Design patterns in brief
Design patterns in briefDesign patterns in brief
Design patterns in brief
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of Patterns
 
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013Common ASP.NET Design Patterns - Telerik India DevCon 2013
Common ASP.NET Design Patterns - Telerik India DevCon 2013
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una Daly
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.ppt
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.ppt
 
Lezione 03 Introduzione a react
Lezione 03   Introduzione a reactLezione 03   Introduzione a react
Lezione 03 Introduzione a react
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 

Recently uploaded

A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
Boost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management AppsBoost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management Apps
Jhone kinadey
 
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLESINTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
anfaltahir1010
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
Benefits of Artificial Intelligence in Healthcare!
Benefits of  Artificial Intelligence in Healthcare!Benefits of  Artificial Intelligence in Healthcare!
Benefits of Artificial Intelligence in Healthcare!
Prestware
 

Recently uploaded (20)

A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
Boost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management AppsBoost Your Savings with These Money Management Apps
Boost Your Savings with These Money Management Apps
 
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLESINTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
Benefits of Artificial Intelligence in Healthcare!
Benefits of  Artificial Intelligence in Healthcare!Benefits of  Artificial Intelligence in Healthcare!
Benefits of Artificial Intelligence in Healthcare!
 

Design Patterns in Cocoa Touch

  • 1. Design Patterns in Cocoa Touch Eliah Snakin
  • 2. Design Pattern a general reusable solution to a commonly occurring problem within a given context GoF
  • 4. MVC Communication Diagram Controller Notify Update Update Events Model View
  • 5. MVC as a Compound Design Pattern Strategy Mediator Observer Composite Command
  • 6. MVC as a Compound Design Pattern Controller Notify Update Update Events Composite Model View Command Mediator Observer Strategy
  • 7. Program to an interface, not an implementation ?
  • 8. Delegation A mechanism by which a host object embeds a weak reference to another object—its delegate—and periodically sends messages to the delegate when it requires its input Template Method Decorator Adapter for a task.
  • 9. Catalogue patterns in Cocoa Touch Prototype Factory Method Abstract Factory Builder Singleton Adapter Bridge Façade Mediator Observer Composite Iterator Visitor Decorator Chain of Responsibility Template Method Strategy Command Flyweight Proxy
  • 10. Prototype Creational GoF:! Specify the kinds of objects to create using a prototypical instance and create new objects by coping the prototype. Cocoa Touch Example:! Prototype cells in UITableView Use dynamic prototypes to design one cell and then use it as the template for other cells in the table. Use a dynamic prototype when multiple cells in a table should use the same layout to display information. - tableView:cellForRowAtIndexPath: - dequeueReusableCellWithIdentifier:
  • 11. Abstract Factory Creational GoF:! Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Cocoa Touch Example:! The interface declared by the abstract superclass, NSNumber (Class cluster) Class clusters group a number of private concrete subclasses under a public abstract superclass.
  • 12. Class cluster Class clusters group a number of private concrete subclasses under a public abstract superclass. The abstract superclass handles instantiation NSNumber *aChar = [NSNumber numberWithChar:’a’]; NSNumber *anInt = [NSNumber numberWithInt:1]; Each object returned by the factory methods belong to a different private subclass which is hidden to users. Apple Documentation
  • 13. Class clusters with Multiple Public Superclasses Apple Documentation
  • 14. Factory Method Creational GoF:! Define an interface for creating an object, but let subclasses decide which class to instantiate. Cocoa Touch Example:! Convenience class-methods, returning instances. NSNumber + numberWithBool: + numberWithChar: …
  • 15. Singleton Creational GoF:! Ensure a class only has one instance, and provide a global point of access to it. Cocoa Touch Example:! UIApplication, UIAccelerometer … UIApplication *applicationSingleton = [UIApplication sharedApplication]; ! UIAccelerometer *accelerometerSingleton = [UIAccelerometer sharedAccelerometer];
  • 16. Singleton + (id)sharedManager { static MyManager *sharedMyManager = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedMyManager = [[self alloc] init]; }); return sharedMyManager; } http://www.galloway.me.uk/tutorials/singleton-classes/
  • 17. Adapter Interface adaptation GoF:! Converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. Cocoa Touch Example:! Delegation — mix of Adapter, Decorator, Template Method Uses Protocol or Block You should always use a class’s delegation mechanism instead of subclassing the class, unless the delegation methods do not allow you to accomplish your goal.
  • 18. Façade Interface adaptation GoF:! Provides a unified interface to a set of interfaces in a system. Façade defines a higher-level interface that makes the subsystem easier to use. Cocoa Touch Example:! NSImage provides a unified interface for loading and using images that can be bitmap-based (such as those in JPEG, PNG, or TIFF format) or vector-based (such as those in EPS or PDF format).
  • 19. Mediator Decoupling GoF:! Defines an object that encapsulates how a set of objects interacts. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently. Cocoa Touch Example:! UIViewController AppKit implements the NSController class and its subclasses. These classes and the bindings technology are not available in iOS.
  • 20. Observer Decoupling GoF:! Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. Cocoa Touch Example:! NSNotification, Key-Value Observing Notifications KVO A central object that provides change notifications for all observers The observed object directly transmits notifications to observers. Mainly concerned with program events in a broad sense Tied to the values of specific object properties
  • 21. Composite Abstract collection GoF:! Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. Cocoa Touch Example:! View Hierarchy — structural architecture that plays a part in both drawing and event handling.
  • 22. Iterator Abstract collection GoF:! Provide a way to access to the elements of an aggregate object sequentially without exposing its underlying representation. Cocoa Touch Example:! NSEnumerator NSEnumerator *itemEnumerator = [anArray objectEnumerator]; NSString *item; while (item = [itemEnumerator nextObject]) { } Block-Based Enumeration ! Fast Enumeration ! Internal Enumeration [anArray enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {}]; for (NSString * item in anArray) {} - (void)makeObjectsPerformSelector:(SEL)aSelector
  • 23. Decorator Behavioural GoF:! Attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. Cocoa Touch Example:! NSAttributedString, NSScrollView, and UIDatePicker Implemented with True Subclasses or Categories.
  • 24. Chain of Responsibility Behavioural GoF:! To avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. It chains the receiving objects and passes the request along the chain until an object handles it. Cocoa Touch Example:! UIResponder If a view is managed by a UIViewController object, the view controller becomes the next responder in the chain (and from there the event or action message passes to the view’s superview).
  • 25. Template Method Algorithm Encapsulation GoF:! Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure. The Template Method pattern is a fundamental design of Cocoa, and indeed of object-oriented frameworks in general. The pattern in Cocoa lets custom components of a program hook themselves into an algorithm, but the framework components determine when and how they are needed.
  • 26. Strategy Algorithm Encapsulation GoF:! Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. Cocoa Touch Example:! a controller determines the behavior of a view about what and when to display the data from a model. The view itself knows how to draw something but doesn’t know what until the controller tells it what to display.
  • 27. Command Algorithm Encapsulation GoF:! Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. Cocoa Touch Example:! NSInvocation, somewhat a target-action mechanism of Cocoa