Cocoa Design Patterns
Upcoming SlideShare
Loading in...5
×
 

Cocoa Design Patterns

on

  • 5,199 views

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

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

Statistics

Views

Total Views
5,199
Views on SlideShare
4,057
Embed Views
1,142

Actions

Likes
6
Downloads
54
Comments
0

9 Embeds 1,142

http://www.stewgleadow.com 867
http://sgleadow.github.com 150
http://melbournepatterns.org 68
http://localhost:4000 31
http://localhost 21
https://twitter.com 2
url_unknown 1
http://twitter.com 1
http://translate.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • - cocoa / objective C: timeline and history\n- Objective C language primer (not too much syntax) -> get a feel for language\n- look at common design patterns in the cocoa world\n
  • relevant to Objective C, Cocoa and Design Patterns\n- smalltalk, graphical OS, popup menus\n
  • Inventors of ObjC worked with Smalltalk in the early 80s\nObjective C aimed at adding some of Smalltalk’s capabilities to C\nThere is a GNU project for the OpenStep standard (but mainly just Apple)\n\n
  • - strict superset of C -> may only write UI layer in Objective C\n- adds SmallTalk style messaging (over C++ block style)\n- runtime small in size, but some overhead\n- performSelector and respondsToSelector\n- uses header files, C structs, function pointers\n
  • - multiple arguments (~ named)\n- strings different for compatibility with C\n
  • Native libraries for OS X, written in Objective C\nUsually built with XCode and Interface Builder\nBridges for Java/Python/Ruby and a few others\n
  • Well thought out and designed library, plenty of design patterns.\nOften not well used.\n
  • Apple often uses their own names\n\n
  • \n
  • - common functionality implemented once\n- allow client code to modify behaviour\n“don’t call us, we’ll call you”\n- delegate: like a single observer, using a protocol\n- set target and action for events, like button tap\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • - implementing the default NSEnumerable protocol means can be used by the inbuilt for loops\n- blocks in Objective C 2.0\n
  • - message passing makes this fairly easy to implement\nrespondsToSelector\nperformSelector\n
  • - Objective C strict superset of C\n- wrapping primitive objects, no auto-boxing\n- access to Carbon APIs\n
  • - can be used and abused\n- Cocoa seems to use it fairly well\n- iPhone users tent to abuse it -> easy global storage\n\n
  • - observer/command\n- becomes easier because of KVC/KVO and dynamic message passing\n- debugging? clarity?\n
  • \n
  • \n
  • \n

Cocoa Design Patterns Cocoa Design Patterns Presentation Transcript

  • Cocoa Design Patterns Stewart Gleadow February 2010
  • 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
  • CObjective C
  • Objective C SyntaxDefinition:- (void)textDidChangeFrom:(NSString *)old to:(NSString *)newText;{}Calling:[textField textDidChangeFrom:@”old text” to:@”new text”];
  • ?
  • Template MVC Enumerators Proxy Method Targets & Flyweight Singleton Delegates Actions ResponderNotifications Hierarchies Invocations Chain
  • Template MVC Enumerators Iterator Proxy Method Targets & Flyweight Singleton Delegates Actions Responder Chain ofNotifications Hierarchies Obser ver Composite Responsibility Invocations Command Chain
  • Template MVC Enumerators Iterator Proxy Method Targets & Flyweight Singleton Delegates Actions Responder Chain ofNotifications Hierarchies Obser ver Composite Responsibility Invocations Command Chain
  • 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)requestDidFinishLoad:(TTURLRequest*)request;@end
  • Delegate@implementation MyDelegate- (void)requestDidStartLoad:(TTURLRequest*)request;{ // start loading indicator?}- (void)requestDidFinishLoad:(TTURLRequest*)request;{ // stop loading indicator // do something awesome}@end
  • DelegateTTURLRequest *request;request = [TTURLRequest requestWithURL:url delegate:myDelegate];
  • Targets & ActionsUIButton *addButton;addButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];[button addTarget:myButtonReceiver action:@selector(addButtonWasPressed:) forControlEvents:UIControlEventTouchUpInside];
  • 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 - Aaron Hillegass• Apple Developer Docs (http:// developer.apple.com)• CocoaHeads (http:// groups.google.com/group/ cocoaheadsau)
  • Stewart Gleadow Thoughtworkssgleadow@thoughtworks.com @stewgleadow