Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Cocoa Design  Patterns  Stewart Gleadow   February 2010
Timeline 1976       1980     1986 1988       1996       2000        2007     2011                                      App...
CObjective C
Objective C SyntaxDefinition:- (void)textDidChangeFrom:(NSString *)old to:(NSString *)newText;{}Calling:[textField textDid...
?
Template   MVC                     Enumerators     Proxy               Method                                         Targ...
Template   MVC                     Enumerators                             Iterator         Proxy               Method    ...
Template   MVC                     Enumerators                             Iterator         Proxy               Method    ...
Template MethodMyView.h#import <UIKit/UIKit.h>@interface MyView : UIView{  // instance variables go here}@end
Template MethodMyView.m#import "MyView.h"@implementation MyView- (void)drawRect:(CGRect)rect;{  // Drawing code.}@end
Delegate@protocol TTURLRequestDelegate <NSObject>  @optional- (void)requestDidStartLoad:(TTURLRequest*)request;- (void)req...
Delegate@implementation MyDelegate- (void)requestDidStartLoad:(TTURLRequest*)request;{  // start loading indicator?}- (voi...
DelegateTTURLRequest *request;request = [TTURLRequest requestWithURL:url delegate:myDelegate];
Targets & ActionsUIButton *addButton;addButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];[button addTarget:myBut...
Enumerator
Proxy
Flyweight
Singleton[[UIApplication sharedApplication] delegate];
Notifications     & Invocations
More?•   Cocoa Design Patterns, by Erik M.    Buck, Donald A.Yacktman•   (Advanced) Cocoa Programming    for Mac OS X - Aa...
Stewart Gleadow    Thoughtworkssgleadow@thoughtworks.com      @stewgleadow
Cocoa Design Patterns
Cocoa Design Patterns
Cocoa Design Patterns
Cocoa Design Patterns
Upcoming SlideShare
Loading in …5
×

Cocoa Design Patterns

6,614 views

Published on

Slides from a presentation I gave on Cocoa Design Patterns - software design patterns that are suitable and common within Apple's Cocoa and Cocoa Touch frameworks using Objective C

  • Be the first to comment

Cocoa Design Patterns

  1. 1. Cocoa Design Patterns Stewart Gleadow February 2010
  2. 2. Timeline 1976 1980 1986 1988 1996 2000 2007 2011 Apple iPhoneOriginal Objective C acquires maniaSmalltalk NeXT NeXT & OS X Mac Commerically NeXTSTEP & app licensed Cocoa store Smalltalk Objective C 2.0
  3. 3. CObjective C
  4. 4. Objective C SyntaxDefinition:- (void)textDidChangeFrom:(NSString *)old to:(NSString *)newText;{}Calling:[textField textDidChangeFrom:@”old text” to:@”new text”];
  5. 5. ?
  6. 6. Template MVC Enumerators Proxy Method Targets & Flyweight Singleton Delegates Actions ResponderNotifications Hierarchies Invocations Chain
  7. 7. Template MVC Enumerators Iterator Proxy Method Targets & Flyweight Singleton Delegates Actions Responder Chain ofNotifications Hierarchies Obser ver Composite Responsibility Invocations Command Chain
  8. 8. Template MVC Enumerators Iterator Proxy Method Targets & Flyweight Singleton Delegates Actions Responder Chain ofNotifications Hierarchies Obser ver Composite Responsibility Invocations Command Chain
  9. 9. Template MethodMyView.h#import <UIKit/UIKit.h>@interface MyView : UIView{ // instance variables go here}@end
  10. 10. Template MethodMyView.m#import "MyView.h"@implementation MyView- (void)drawRect:(CGRect)rect;{ // Drawing code.}@end
  11. 11. Delegate@protocol TTURLRequestDelegate <NSObject> @optional- (void)requestDidStartLoad:(TTURLRequest*)request;- (void)requestDidFinishLoad:(TTURLRequest*)request;@end
  12. 12. Delegate@implementation MyDelegate- (void)requestDidStartLoad:(TTURLRequest*)request;{ // start loading indicator?}- (void)requestDidFinishLoad:(TTURLRequest*)request;{ // stop loading indicator // do something awesome}@end
  13. 13. DelegateTTURLRequest *request;request = [TTURLRequest requestWithURL:url delegate:myDelegate];
  14. 14. Targets & ActionsUIButton *addButton;addButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];[button addTarget:myButtonReceiver action:@selector(addButtonWasPressed:) forControlEvents:UIControlEventTouchUpInside];
  15. 15. Enumerator
  16. 16. Proxy
  17. 17. Flyweight
  18. 18. Singleton[[UIApplication sharedApplication] delegate];
  19. 19. Notifications & Invocations
  20. 20. More?• Cocoa Design Patterns, by Erik M. Buck, Donald A.Yacktman• (Advanced) Cocoa Programming for Mac OS X - Aaron Hillegass• Apple Developer Docs (http:// developer.apple.com)• CocoaHeads (http:// groups.google.com/group/ cocoaheadsau)
  21. 21. Stewart Gleadow Thoughtworkssgleadow@thoughtworks.com @stewgleadow

×