SlideShare una empresa de Scribd logo
1 de 28
Descargar para leer sin conexión
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 :)

Más contenido relacionado

La actualidad más candente

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 PatternsLalit 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 ScalaFilip 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 TransformationCoen De Roover
 
Strategy Design Pattern
Strategy Design PatternStrategy Design Pattern
Strategy Design PatternGanesh 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 javaKavitha713564
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3Naga Muruga
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsMichael Heron
 
PATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsPATTERNS02 - Creational Design Patterns
PATTERNS02 - Creational Design PatternsMichael Heron
 
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 munichtschuetz
 
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_19Niit 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_08Niit Care
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascriptrelay12
 

La actualidad más candente (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
 

Destacado

Design patterns
Design patternsDesign patterns
Design patternsISsoft
 
Design patterns - Abstract Factory Pattern
Design patterns  - Abstract Factory PatternDesign patterns  - Abstract Factory Pattern
Design patterns - Abstract Factory PatternAnnamalai Chockalingam
 
Design Pattern - 2. Observer
Design Pattern -  2. ObserverDesign Pattern -  2. Observer
Design Pattern - 2. ObserverFrancesco 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 patternbabak danyal
 
Observer Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 AugObserver Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 Augmelbournepatterns
 
Design patterns 4 - observer pattern
Design patterns   4 - observer patternDesign patterns   4 - observer pattern
Design patterns 4 - observer patternpixelblend
 
Design patterns: observer pattern
Design patterns: observer patternDesign patterns: observer pattern
Design patterns: observer patternJyaasa Technologies
 
Reflective portfolio
Reflective portfolioReflective portfolio
Reflective portfoliojobbo1
 
Design Pattern - Observer Pattern
Design Pattern - Observer PatternDesign Pattern - Observer Pattern
Design Pattern - Observer PatternMudasir Qazi
 
Observer design pattern
Observer design patternObserver design pattern
Observer design patternSara Torkey
 
Observer Pattern
Observer PatternObserver Pattern
Observer PatternAkshat Vig
 
Observer design pattern
Observer design patternObserver design pattern
Observer design patternSameer Rathoud
 

Destacado (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 a 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.docxdanhaley45372
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav 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 PatternNishith Shukla
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patternspradeepkothiyal
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptMsRAMYACSE
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 
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 briefDUONG Trong Tan
 
Evolution of Patterns
Evolution of PatternsEvolution of Patterns
Evolution of PatternsChris 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 2013Steven Smith
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano 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 DalyUna Daly
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.pptAnkitPangasa1
 
lecture10-patterns.ppt
lecture10-patterns.pptlecture10-patterns.ppt
lecture10-patterns.pptbryafaissal
 
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 PatternsJason Townsend, MBA
 

Similar a 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
 

Último

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 

Último (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

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