Delegation

625
-1

Published on

A presentation given at MobileDevNJ about Delegation patterns on the iOS platform.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
625
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
53
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Delegation

    1. 1. Delegation Object Messaging
    2. 2. What is Delegation?Delegation is a design pattern in object-orientedprogramming where an object, instead ofperforming one of its stated tasks, delegates thattask to an associated helper object. It passes thebuck, so to speak (technically, an Inversion ofResponsibility).The helper object is called the delegate. (source:Wikepedia)
    3. 3. Examples: AppDelegate• UIApplicationDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions - (void)applicationWillTerminate: (UIApplication *)application
    4. 4. Examples: UITableView• UITableViewDelegate - UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - ...tableView:didDeselectRowAtIndexPath:
    5. 5. What Problem Does Delegation Solve? Object A Object B
    6. 6. Write to File Object A Object B (Equipment) (User Interface) somefile.txt
    7. 7. Define Pointers Object A Object B (Equipment) (User Interface)ObjectB *myObject;myObject = [self getSomeData:data];
    8. 8. App Delegate Define Property Object A Object B (Equipment) (User Interface)AppDelegate *d = [[UIApplication sharedApplication] delegate];d.someString = ...
    9. 9. App Delegate Define Delegate Object A Object B (Equipment) (User Interface)• Create Delegate Object • Helper App• Defines Protocols • Delegate of Object A - List of methods • Implements Protocol
    10. 10. Demo• Build a Program using Delegation

    ×